package com.millennialmedia.android;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.net.Uri;
import android.text.TextUtils;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

class MRaid
{
  private static final String KEY_MMJS_URL = "KEY_MMJS_URL";
  private static final String MMJS_1_3_PART1 = "LyoqCiogTWlsbGVubmlhbCBNZWRpYSBKUyBMaWJyYXJ5IChNTS5qcykKKiBDb3B5cmlnaHQgMjAxMC0yMDEzLCBNaWxsZW5uaWFsIE1lZGlhCioKKiBCdWlsdCBvbiBUaHUgQXByIDA0IDIwMTMgMTE6MDk6MTEgR01ULTA3MDAgKFBEVCkuCiovCgovLyBHZW5lcmF0ZWQgYnkgQ29mZmVlU2NyaXB0IDEuMy4zCnZhciBNTUFwcFN0b3JlLCBNTUJhbm5lciwgTU1CcmFuZCwgTU1CcmlkZ2VPYmplY3QsIE1NQ2FjaGVkVmlkZW8sIE1NQ2FsZW5kYXIsIE1NQ29tbWFuZCwgTU1EZXZpY2UsIE1NRmlsZU1hbmFnZXIsIE1NSW5saW5lVmlkZW8sIE1NSW50ZXJzdGl0aWFsLCBNTUpTLCBNTUpTVXRpbHMsIE1NTWVkaWEsIE1NTm90aWZpY2F0aW9uLCBNTVBhc3Nib29rLCBNTVBhc3RlYm9hcmQsIE1NU0RLSW50ZXJmYWNlLCBNTVNvY2lhbCwgTVJBSUQsCiAgX19oYXNQcm9wID0ge30uaGFzT3duUHJvcGVydHksCiAgX19leHRlbmRzID0gZnVuY3Rpb24oY2hpbGQsIHBhcmVudCkgeyBmb3IgKHZhciBrZXkgaW4gcGFyZW50KSB7IGlmIChfX2hhc1Byb3AuY2FsbChwYXJlbnQsIGtleSkpIGNoaWxkW2tleV0gPSBwYXJlbnRba2V5XTsgfSBmdW5jdGlvbiBjdG9yKCkgeyB0aGlzLmNvbnN0cnVjdG9yID0gY2hpbGQ7IH0gY3Rvci5wcm90b3R5cGUgPSBwYXJl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aXNCcmlkZ2VFbmFibGVkKCkgPT09IHRydWUpIHsKICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgIH0KICAgICAgaWYgKGEgPT0gbnVsbCkgewogICAgICAgIHJldHVybiB0cnVlOwogICAgICB9CiAgICAgIHJldHVybiB0aGlzLnVuZGVyVmVyc2lvbihhLCAiNC42LjAiKTsKICAgIH07CgogICAgTU1KU1V0aWxzLnVuZGVyVmVyc2lvbiA9IGZ1bmN0aW9uKHZlcnNpb25TdHJpbmcsIG1pblZlcnNpb24pIHsKICAgICAgdmFyIGksIHJlcywgcmVzdWx0LCB2MSwgdjI7CiAgICAgIGlmICh2ZXJzaW9uU3RyaW5nID09IG51bGwpIHsKICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgIH0KICAgICAgdjEgPSB2ZXJzaW9uU3RyaW5nLnNwbGl0KCIuIik7CiAgICAgIHYyID0gbWluVmVyc2lvbi5zcGxpdCgiLiIpOwogICAgICBpID0gMDsKICAgICAgcmVzdWx0ID0gMDsKICAgICAgd2hpbGUgKGkgPCBNYXRoLm1pbih2MS5sZW5ndGgsIHYyLmxlbmd0aCkpIHsKICAgICAgICByZXMgPSB2MVtpXSAtIHYyW2ldOwogICAgICAgIGlmIChyZXMgIT09IDApIHsKICAgICAgICAgIHJlc3VsdCA9IHJlczsKICAgICAgICAgIGJyZWFrOwogICAgICAgIH0KICAgICAgICBpKys7CiAgICAgIH0KICAgICAgcmV0dXJuIHJlc3VsdCA8IDA7CiAgICB9OwoKICAgIE1NSlNVdGlscy5pc1ZlcnNpb24gPSBmdW5jdGlvbih2ZXJzaW9uU3RyaW5nKSB7CiAgICAgIHZhciBpLCByZXMsIHJlc3VsdCwgdjEsIHYyOwogICAgICBpZiAodmVyc2lvblN0cmluZyA9PSBudWxsKSB7CiAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICB9CiAgICAgIHYxID0gdmVyc2lvblN0cmluZy5zcGxpdCgiLiIpOwogICAgICB2MiA9IHRoaXMuc2Rr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5rVGFnLmlkID0gIm1tX3NpbXVsYXRlTGluayI7CiAgICAgIGxpbmtUYWcuc2V0QXR0cmlidXRlKCJocmVmIiwgdXJsKTsKICAgICAgbGlua1RhZy5zZXRBdHRyaWJ1dGUoInN0eWxlIiwgIm9wYWNpdHk6MCIpOwogICAgICBkb2N1bWVudC5ib2R5LmFwcGVuZENoaWxkKGxpbmtUYWcpOwogICAgICBldmVudEZpcmUgPSBmdW5jdGlvbihlbCwgZXR5cGUpIHsKICAgICAgICB2YXIgZXZPYmo7CiAgICAgICAgaWYgKGVsLmZpcmVFdmVudCkgewogICAgICAgICAgcmV0dXJuIGVsLmZpcmVFdmVudCgib24iICsgZXR5cGUpOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBldk9iaiA9IGRvY3VtZW50LmNyZWF0ZUV2ZW50KCJFdmVudHMiKTsKICAgICAgICAgIGV2T2JqLmluaXRFdmVudChldHlwZSwgdHJ1ZSwgZmFsc2UpOwogICAgICAgICAgcmV0dXJuIGVsLmRpc3BhdGNoRXZlbnQoZXZPYmopOwogICAgICAgIH0KICAgICAgfTsKICAgICAgcmV0dXJuIHdpbmRvdy5zZXRUaW1lb3V0KChmdW5jdGlvbigpIHsKICAgICAgICB2YXIgZWxlbWVudDsKICAgICAgICBlbGVtZW50ID0gbGlua1RhZzsKICAgICAgICByZXR1cm4gZXZlbnRGaXJlKGxpbmtUYWcsICJjbGljayIpOwogICAgICB9KSwgMSk7CiAgICB9OwoKICAgIE1NSlNVdGlscy5tb2REdXJhdGlvbiA9IGZ1bmN0aW9uKGR1cmF0aW9uKSB7CiAgICAgIGlmICghdGhpcy5pc0FuZHJvaWQoKSkgewogICAgICAgIHJldHVybiBkdXJhdGlvbjsKICAgICAgfQogICAgICBpZiAoZHVyYXRpb24gPCAxMDApIHsKICAgICAgICByZXR1cm4gZHVyYXRpb24gKiAxMDAwOwogICAgICB9IGVsc2UgewogICAgICAgIHJldHVybiBkdXJhdGlvbjsKICAgICAgfQogICAgfTsK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cy5wYXJhbXMgPSBwYXJhbXM7CiAgICAgIHJldHVybiB0aGlzLnBhcmFtczsKICAgIH07CgogICAgTU1KU1V0aWxzLmNvbnNvbGVMb2cgPSBmdW5jdGlvbihfbXNnLCBfdXNlQWxlcnQpIHsKICAgICAgaWYgKF91c2VBbGVydCA9PSBudWxsKSB7CiAgICAgICAgX3VzZUFsZXJ0ID0gZmFsc2U7CiAgICAgIH0KICAgICAgTU1KUy5ldmVudFRyYWNraW5nLnB1c2goX21zZyk7CiAgICAgIGlmICh0aGlzLmlzQW5kcm9pZCgpKSB7CiAgICAgICAgaWYgKHdpbmRvdy5jb25zb2xlICE9IG51bGwpIHsKICAgICAgICAgIHdpbmRvdy5jb25zb2xlLmxvZyhfbXNnKTsKICAgICAgICB9CiAgICAgIH0gZWxzZSBpZiAodGhpcy5pc1dpbmRvd3MoKSkgewogICAgICAgIHdpbmRvdy5leHRlcm5hbC5ub3RpZnkoX21zZyk7CiAgICAgIH0gZWxzZSB7CiAgICAgICAgaWYgKHdpbmRvdy5jb25zb2xlICE9IG51bGwpIHsKICAgICAgICAgIHdpbmRvdy5jb25zb2xlLmxvZyhfbXNnKTsKICAgICAgICB9CiAgICAgICAgaWYgKF91c2VBbGVydCkgewogICAgICAgICAgYWxlcnQoX21zZyk7CiAgICAgICAgfQogICAgICB9CiAgICAgIHJldHVybiBmYWxzZTsKICAgIH07CgogICAgTU1KU1V0aWxzLmlPU1ZlcnNpb24gPSBmdW5jdGlvbigpIHsKICAgICAgdmFyIF92OwogICAgICBpZiAodGhpcy5pb3NfdmVyc2lvbikgewogICAgICAgIHJldHVybiB0aGlzLmlvc192ZXJzaW9uOwogICAgICB9CiAgICAgIF92ID0gbmF2aWdhdG9yLmFwcFZlcnNpb24uc3BsaXQoJyBPUyAnKVsxXTsKICAgICAgX3YgPSBfdi5zcGxpdCgnICcpWzBdLnRyaW0oKS5zcGxpdCgnXycpOwogICAgICBfdi5zcGxpY2UoMSwgMCwgJy4nKTsKICAgICAgcm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GFyYW1zKTsKICAgICAgcmV0dXJuIG1yYWlkLmV4cGFuZCh1cmwpOwogICAgfTsKCiAgICBNTUpTLmNsb3NlID0gZnVuY3Rpb24oZHVyYXRpb24pIHsKICAgICAgdmFyIG1vZER1cmF0aW9uOwogICAgICBpZiAoZHVyYXRpb24gPT0gbnVsbCkgewogICAgICAgIGR1cmF0aW9uID0gMDsKICAgICAgfQogICAgICBtb2REdXJhdGlvbiA9IGZ1bmN0aW9uKGR1cmF0aW9uKSB7CiAgICAgICAgaWYgKGR1cmF0aW9uIDwgMTAwKSB7CiAgICAgICAgICByZXR1cm4gZHVyYXRpb24gKiAxMDAwOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICByZXR1cm4gZHVyYXRpb247CiAgICAgICAgfQogICAgICB9OwogICAgICByZXR1cm4gc2V0VGltZW91dChmdW5jdGlvbigpIHsKICAgICAgICByZXR1cm4gTU1KUy5pbnRlcnN0aXRpYWwuY2xvc2UoKTsKICAgICAgfSwgbW9kRHVyYXRpb24oZHVyYXRpb24pKTsKICAgIH07CgogICAgTU1KUy5vcGVuRXh0ZXJuYWwgPSBmdW5jdGlvbih1cmwpIHsKICAgICAgaWYgKHRoaXMudXRpbHMuaXNCcmlkZ2VFbmFibGVkKCkpIHsKICAgICAgICByZXR1cm4gTU1EZXZpY2Uub3BlblVybCh1cmwpOwogICAgICB9IGVsc2UgewogICAgICAgIGlmICh0aGlzLnV0aWxzLmlzSU9TKCkpIHsKICAgICAgICAgIHJldHVybiB3aW5kb3cubG9jYXRpb24gPSAibW1icm93c2VyOjovLyIgKyB1cmw7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIHJldHVybiB3aW5kb3cubG9jYXRpb24gPSAibW1icm93c2VyOi8vIiArIHVybDsKICAgICAgICB9CiAgICAgIH0KICAgIH07CgogICAgTU1KUy5yZW1vdmVFdmVudExpc3RlbmVyID0gZnVuY3Rpb24oZXZlbnQsIGxpc3RlbmVyKSB7CiAgICAgIHJldHVybiBkZW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ICAgICAgICAgICAgICBjb250ZXh0ID0gY29udGV4dFtuYW1lc3BhY2VzW2ldXTsKICAgICAgICAgICAgICBpKys7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgTU1KUy51dGlscy5jb25zb2xlTG9nKCJhRnVuYzogIiArIGFGdW5jKTsKICAgICAgICAgICAgTU1KUy51dGlscy5jb25zb2xlTG9nKCJjb250ZXh0OiAiICsgY29udGV4dCk7CiAgICAgICAgICAgIGNvbnRleHRbYUZ1bmNdKHJlc3BvbnNlKTsKICAgICAgICAgICAgcmV0dXJuIE1NSlMuc2V0RXhlY3V0aW5nQ29tbWFuZChmYWxzZSk7CiAgICAgICAgICB9OwogICAgICAgIH0gZWxzZSBpZiAodHlwZW9mIGZ1bmMgPT09IE1NSlMuVFlQRV9GVU5DVElPTikgewogICAgICAgICAgd2luZG93WyJNTUpTIl1bImNhbGxiYWNrcyJdW2Z1bmN0aW9uTmFtZV0gPSBmdW5jdGlvbihyZXNwb25zZSkgewogICAgICAgICAgICBpZiAocmVzcG9uc2UgIT0gbnVsbCkgewogICAgICAgICAgICAgIHJlc3BvbnNlWydkYXRhJ10gPSByZXNwb25zZVsncmVzcG9uc2UnXTsKICAgICAgICAgICAgICByZXNwb25zZVsncmVzdWx0J10gPSBwYXJzZUludChyZXNwb25zZVsncmVzdWx0J10pOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGZ1bmMocmVzcG9uc2UpOwogICAgICAgICAgICByZXR1cm4gTU1KUy5zZXRFeGVjdXRpbmdDb21tYW5kKGZhbHNlKTsKICAgICAgICAgIH07CiAgICAgICAgfSBlbHNlIGlmICh0eXBlb2YgZnVuYyA9PT0gTU1KUy5UWVBFX1VOREVGSU5FRCkgewogICAgICAgICAgd2luZG93WyJNTUpTIl1bImNhbGxiYWNrcyJdW2Z1bmN0aW9uTmFtZV0gPSBmdW5jdGlvbihyZXNwb25zZSkgewogICAgICAgICAgICBNTUpTLnV0aWxzLmNvbnNvbGVMb2coImV4ZWN1dGluZyB1bmRlZmluZWQgY2FsbGJhY2s6ICIgKyBmdW5jdGlvbk5hbWUpOwogICAgICAgICAgICBNTUpTLnV0aWxzLmNvbnNvbGVMb2coIm5vIGNhbGxiYWNrIHdhcyBzcGVjaWZpZWQiKTsKICAgICAgICAgICAgcmV0dXJuIE1NSlMuc2V0RXhlY3V0aW5nQ29tbWFuZChmYWxzZSk7CiAgICAgICAgICB9OwogICAgICAgIH0KICAgICAgICBwYXJhbXNbImNhbGxiYWNrIl0gPSAiTU1KUy5jYWxsYmFja3MuIiArIGZ1bmN0aW9uTmFtZTsKICAgICAgICB0aGlzLmNhbGxiYWNrID0gcGFyYW1zWyJjYWxsYmFjayJdOwogICAgICAgIGZvciAobmFtZSBpbiBwYXJhbXMpIHsKICAgICAgICAgIGlmICh0eXBlb2YgbmFtZSAhPT0gTU1KUy5UWVBFX1NUUklORykgewogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChwYXJhbXNbbmFtZV0gPT09IHZvaWQgMCB8fCBwYXJhbXNbbmFtZV0gPT09IG51bGwpIHsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBxdWVyeV9hcmdzLnB1c2goZW5jb2RlVVJJQ29tcG9uZW50KG5hbWUpICsgIj0iICsgZW5jb2RlVVJJQ29tcG9uZW50KHBhcmFtc1tuYW1lXSkpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAocXVlcnlfYXJncy5sZW5ndGggPiAwKSB7CiAgICAgICAgICB1cmwgKz0gIj8iICsgcXVlcnlfYXJncy5qb2luKCImIik7CiAgICAgICAgfQogICAgICB9CiAgICAgIE1NSlMudXRpbHMuY29uc29sZUxvZyh1cmwpOwogICAgICB0aGlzLnVybCA9IHVybDsKICAgICAgdGhpczsKCiAgICB9CgogICAgTU1Db21tYW5kLnByb3RvdHlwZS5wZXJmb3JtID0gZnVuY3Rpb24oKSB7CiAgICAgIHZhciBpZnJhb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PSBtWzFdOwogICAgICB9CiAgICB9CgogICAgTU1CcmlkZ2VPYmplY3QucHJvdG90eXBlLmVucXVldWUgPSBmdW5jdGlvbihtZXRob2QsIHBhcmFtcykgewogICAgICBNTUpTLmVucXVldWVDb21tYW5kKG5ldyBNTUNvbW1hbmQodGhpcy5jbGFzc05hbWUgKyAiLiIgKyBtZXRob2QsIHBhcmFtcykpOwogICAgICByZXR1cm4gdHJ1ZTsKICAgIH07CgogICAgcmV0dXJuIE1NQnJpZGdlT2JqZWN0OwoKICB9KSgpOwogIE1NRGV2aWNlID0gKGZ1bmN0aW9uKF9zdXBlcikgewoKICAgIF9fZXh0ZW5kcyhNTURldmljZSwgX3N1cGVyKTsKCiAgICBmdW5jdGlvbiBNTURldmljZSgpIHsKICAgICAgcmV0dXJuIE1NRGV2aWNlLl9fc3VwZXJfXy5jb25zdHJ1Y3Rvci5hcHBseSh0aGlzLCBhcmd1bWVudHMpOwogICAgfQoKICAgIE1NRGV2aWNlLmxvYWRTdGF0ZSA9ICJzdGFuZGJ5IjsKCiAgICBNTURldmljZS5sb2FkVGltZW91dCA9IDA7CgogICAgTU1EZXZpY2UuY29ubmVjdGlvbiA9IG51bGw7CgogICAgTU1EZXZpY2UucHJvdG90eXBlLnNldE5ldHdvcmtDb25uZWN0aW9uID0gZnVuY3Rpb24obmV0d29yaykgewogICAgICByZXR1cm4gdGhpcy5jb25uZWN0aW9uID0gbmV0d29yazsKICAgIH07CgogICAgTU1EZXZpY2UucHJvdG90eXBlLnNldEluZm8gPSBmdW5jdGlvbihpbmZvKSB7CiAgICAgIHZhciBldnQsIGtleSwgdmFsdWU7CiAgICAgIGZvciAoa2V5IGluIGluZm8pIHsKICAgICAgICB2YWx1ZSA9IGluZm9ba2V5XTsKICAgICAgICB0aGlzW2tleV0gPSB2YWx1ZTsKICAgICAgfQogICAgICBNTURldmljZS5sb2FkU3RhdGUgPSAibG9hZGVkIjsKICAgICAgaWYgKCF0aGlzLnV0aWxzLmlzV2luZG93cyg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YWNrOiBjYWxsYmFjawogICAgICB9KTsKICAgIH07CgogICAgTU1EZXZpY2UucHJvdG90eXBlLmdldEF2YWlsYWJsZVNjaGVtZXMgPSBmdW5jdGlvbihjYWxsYmFjaykgewogICAgICByZXR1cm4gdGhpcy5lbnF1ZXVlKCJnZXRBdmFpbGFibGVTY2hlbWVzIiwgewogICAgICAgIGNhbGxiYWNrOiBjYWxsYmFjawogICAgICB9KTsKICAgIH07CgogICAgTU1EZXZpY2UucHJvdG90eXBlLmdldE9yaWVudGF0aW9uID0gZnVuY3Rpb24oY2FsbGJhY2spIHsKICAgICAgcmV0dXJuIHRoaXMuZW5xdWV1ZSgiZ2V0T3JpZW50YXRpb24iLCB7CiAgICAgICAgY2FsbGJhY2s6IGNhbGxiYWNrCiAgICAgIH0pOwogICAgfTsKCiAgICBNTURldmljZS5wcm90b3R5cGUuZ2V0TG9jYXRpb24gPSBmdW5jdGlvbihjYWxsYmFjaykgewogICAgICByZXR1cm4gdGhpcy5lbnF1ZXVlKCJnZXRMb2NhdGlvbiIsIHsKICAgICAgICBjYWxsYmFjazogY2FsbGJhY2sKICAgICAgfSk7CiAgICB9OwoKICAgIE1NRGV2aWNlLnByb3RvdHlwZS5zaG93TWFwID0gZnVuY3Rpb24obG9jYXRpb24sIGNhbGxiYWNrKSB7CiAgICAgIHJldHVybiB0aGlzLmVucXVldWUoInNob3dNYXAiLCB7CiAgICAgICAgbG9jYXRpb246IGxvY2F0aW9uLAogICAgICAgIGNhbGxiYWNrOiBjYWxsYmFjawogICAgICB9KTsKICAgIH07CgogICAgTU1EZXZpY2UucHJvdG90eXBlLmNhbGwgPSBmdW5jdGlvbihudW1iZXIsIGRpYWwsIGNhbGxiYWNrKSB7CiAgICAgIHJldHVybiB0aGlzLmVucXVldWUoImNhbGwiLCB7CiAgICAgICAgbnVtYmVyOiBudW1iZXIsCiAgICAgICAgY2FsbGJhY2s6IGNhbGxiYWNrLAogICAgICAgIGRpYWw6IGRpYWwKICAgICAgfSk7CiAgICB9OwoKICAgIE1NRGV2aWNlLnByb3RvdHlwZS5vcGVuVXJsID0gZnVuY3Rpb24odXJsLCBjYWxsYmFjaykgewogICAgICByZXR1cm4gdGhpcy5lbnF1ZXVlKCJvcGVuVXJsIiwgewogICAgICAgIHVybDogdXJsLAogICAgICAgIGNhbGxiYWNrOiBjYWxsYmFjawogICAgICB9KTsKICAgIH07CgogICAgTU1EZXZpY2UucHJvdG90eXBlLm9wZW5BcHBTdG9yZSA9IGZ1bmN0aW9uKGFwcElkLCBjYWxsYmFjaykgewogICAgICByZXR1cm4gdGhpcy5lbnF1ZXVlKCJvcGVuQXBwU3RvcmUiLCB7CiAgICAgICAgYXBwSWQ6IGFwcElkLAogICAgICAgIGNhbGxiYWNrOiBjYWxsYmFjawogICAgICB9KTsKICAgIH07CgogICAgTU1EZXZpY2UucHJvdG90eXBlLmNvbXBvc2VTTVMgPSBmdW5jdGlvbihudW1iZXIsIG1lc3NhZ2UsIGNhbGxiYWNrKSB7CiAgICAgIHJldHVybiB0aGlzLmNvbXBvc2VTbXMobnVtYmVyLCBtZXNzYWdlLCBjYWxsYmFjayk7CiAgICB9OwoKICAgIE1NRGV2aWNlLnByb3RvdHlwZS5jb21wb3NlU21zID0gZnVuY3Rpb24obnVtYmVyLCBtZXNzYWdlLCBjYWxsYmFjaykgewogICAgICBpZiAodGhpcy51dGlscy5pc0lPUygpKSB7CiAgICAgICAgcmV0dXJuIHRoaXMuZW5xdWV1ZSgiY29tcG9zZVNtcyIsIHsKICAgICAgICAgIG51bWJlcjogbnVtYmVyLAogICAgICAgICAgbWVzc2FnZTogbWVzc2FnZSwKICAgICAgICAgIGNhbGxiYWNrOiBjYWxsYmFjawogICAgICAgIH0pOwogICAgICB9IGVsc2UgewogICAgICAgIHJldHVybiB0aGlzLmVucXVldWUoImNvbXBvc2VTbXMiLCB7CiAgICAgICAgICBudW1iZXI6IG51bWJlciwKICAgICAgICAgIG1lc3NhZ2U6IG1lc3NhZ2UsCiAgICAgICAgICBjYWxsYmFjazogY2FsbGJhY2sKICAgICAgICB9KTsKICAgICAgfQogICAgfTsKCiAgICBNTURldmljZS5wcm90b3R5cGUuY29tcG9zZUVtYWlsID0gZnVuY3Rpb24ocmVjaXBpZW50LCBzdWJqZWN0LCBtZXNzYWdlLCBjYWxsYmFjaykgewogICAgICBpZiAodGhpcy51dGlscy5pc0lPUygpKSB7CiAgICAgICAgcmV0dXJuIHRoaXMub3BlblVybCgibWFpbHRvOj90bz0iICsgZW5jb2RlVVJJQ29tcG9uZW50KHJlY2lwaWVudCkgKyAiJnN1YmplY3Q9IiArIGVuY29kZVVSSUNvbXBvbmVudChzdWJqZWN0KSArICImYm9keT0iICsgZW5jb2RlVVJJQ29tcG9uZW50KG1lc3NhZ2UpLCBjYWxsYmFjayk7CiAgICAgIH0gZWxzZSB7CiAgICAgICAgcmV0dXJuIHRoaXMuZW5xdWV1ZSgiY29tcG9zZUVtYWlsIiwgewogICAgICAgICAgcmVjaXBpZW50OiByZWNpcGllbnQsCiAgICAgICAgICBzdWJqZWN0OiBzdWJqZWN0LAogICAgICAgICAgbWVzc2FnZTogbWVzc2FnZSwKICAgICAgICAgIGNhbGxiYWNrOiBjYWxsYmFjawogICAgICAgIH0pOwogICAgICB9CiAgICB9OwoKICAgIE1NRGV2aWNlLnByb3RvdHlwZS5nZXRDb21wYXNzSGVhZGluZyA9IGZ1bmN0aW9uKGNhbGxiYWNrKSB7CiAgICAgIHJldHVybiB0aGlzLmVucXVldWUoImdldENvbXBhc3NIZWFkaW5nIiwgewogICAgICAgIGNhbGxiYWNrOiBjYWxsYmFjawogICAgICB9KTsKICAgIH07CgogICAgTU1EZXZpY2UucHJvdG90eXBlLmdldEJhcm9tZXRlciA9IGZ1bmN0aW9uKGNhbGxiYWNrKSB7CiAgICAgIHJldHVybiB0aGlzLmVucXVldWUoImdldEJhcm9tZXRlciIsIHsKICAgICAgICBjYWxsYmFjazogY2FsbGJhY2sKICAgICAgfSk7CiAgICB9OwoKICAgIE1NR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ICAgICAgICAgIH0pOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICByZXR1cm4gY2FsbGJhY2soewogICAgICAgICAgICAicmVzdWx0IjogMCwKICAgICAgICAgICAgInJlc3BvbnNlIjogImNhY2hlZFZpZGVvVVJJIG9yIHN0cmVhbVZpZGVvVVJJIG5vdCBmb3VuZCIsCiAgICAgICAgICAgICJjbGFzcyI6ICJNTUlubGluZVZpZGVvIiwKICAgICAgICAgICAgImNhbGwiOiAiaW5zZXJ0VmlkZW8iCiAgICAgICAgICB9KTsKICAgICAgICB9CiAgICAgIH0gZWxzZSB7CiAgICAgICAgcmV0dXJuIGNhbGxiYWNrKHsKICAgICAgICAgICJyZXN1bHQiOiAwLAogICAgICAgICAgInJlc3BvbnNlIjogIkRpdiBJZCBub3QgZm91bmQiLAogICAgICAgICAgImNsYXNzIjogIk1NSW5saW5lVmlkZW8iLAogICAgICAgICAgImNhbGwiOiAiaW5zZXJ0VmlkZW8iCiAgICAgICAgfSk7CiAgICAgIH0KICAgIH07CgogICAgTU1JbmxpbmVWaWRlby5wcm90b3R5cGUuaW5zZXJ0VmlkZW8gPSBmdW5jdGlvbih0aW1pbmdDYWxsYmFjaywgY2FsbGJhY2spIHsKICAgICAgcmV0dXJuIHRoaXMuaW5zZXJ0VmlkZW9XaXRoSWQoJ2lubGluZVZpZGVvJywgdGltaW5nQ2FsbGJhY2ssIGNhbGxiYWNrKTsKICAgIH07CgogICAgTU1JbmxpbmVWaWRlby5wcm90b3R5cGUuY2FsY3VsYXRlRGl2UG9zaXRpb24gPSBmdW5jdGlvbihkaXZJZCkgewogICAgICB2YXIgZGl2RWwsIGhlaWdodCwgcG9zaXRpb24sIHdpZHRoLCB4LCB5OwogICAgICBkaXZFbCA9IGRvY3VtZW50LmdldEVsZW1lbnRCeUlkKGRpdklkKTsKICAgICAgcG9zaXRpb24gPSB0aGlzLnV0aWxzLm9mZnNldChkaXZFbCk7CiAgICAgIHggPSBwb3NpdGlvblswXTsKICAgICAge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H07CgogICAgTU1DYWNoZWRWaWRlby5wcm90b3R5cGUuc2V0RXJyb3IgPSBmdW5jdGlvbihlcnJvcikgewogICAgICBpZiAodGhpcy5lcnJvckNhbGxiYWNrICE9IG51bGwpIHsKICAgICAgICByZXR1cm4gdGhpcy5lcnJvckNhbGxiYWNrKGVycm9yKTsKICAgICAgfQogICAgfTsKCiAgICBNTUNhY2hlZFZpZGVvLnByb3RvdHlwZS5zZXRFcnJvckNhbGxiYWNrID0gZnVuY3Rpb24oZXJyb3JDYWxsYmFjaykgewogICAgICByZXR1cm4gdGhpcy5lcnJvckNhbGxiYWNrID0gZXJyb3JDYWxsYmFjazsKICAgIH07CgogICAgTU1DYWNoZWRWaWRlby5wcm90b3R5cGUucmVzdGFydFZpZGVvID0gZnVuY3Rpb24oY2FsbGJhY2spIHsKICAgICAgcmV0dXJuIHRoaXMuZW5xdWV1ZSgicmVzdGFydFZpZGVvIiwgewogICAgICAgIGNhbGxiYWNrOiBjYWxsYmFjawogICAgICB9KTsKICAgIH07CgogICAgTU1DYWNoZWRWaWRlby5wcm90b3R5cGUuZW5kVmlkZW8gPSBmdW5jdGlvbihjYWxsYmFjaykgewogICAgICByZXR1cm4gdGhpcy5lbnF1ZXVlKCJlbmRWaWRlbyIsIHsKICAgICAgICBjYWxsYmFjazogY2FsbGJhY2sKICAgICAgfSk7CiAgICB9OwoKICAgIE1NQ2FjaGVkVmlkZW8ucHJvdG90eXBlLnBhdXNlVmlkZW8gPSBmdW5jdGlvbihjYWxsYmFjaykgewogICAgICByZXR1cm4gdGhpcy5lbnF1ZXVlKCJwYXVzZVZpZGVvIiwgewogICAgICAgIGNhbGxiYWNrOiBjYWxsYmFjawogICAgICB9KTsKICAgIH07CgogICAgTU1DYWNoZWRWaWRlby5wcm90b3R5cGUucGxheVZpZGVvID0gZnVuY3Rpb24oY2FsbGJhY2spIHsKICAgICAgcmV0dXJuIHRoaXMuZW5xdWV1ZSgicGxheVZpZGVvIiwgewogICAgICAgIGNhbGxi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AgICB1c2VDdXN0b21DbG9zZTogdXNlQ3VzdG9tQ2xvc2UsCiAgICAgICAgY2FsbGJhY2s6IGNhbGxiYWNrCiAgICAgIH0pOwogICAgfTsKCiAgICBNTUludGVyc3RpdGlhbC5wcm90b3R5cGUuc2V0T3JpZW50YXRpb24gPSBmdW5jdGlvbihwcm9wZXJ0aWVzLCBjYWxsYmFjaykgewogICAgICBwcm9wZXJ0aWVzWyJjYWxsYmFjayJdID0gY2FsbGJhY2s7CiAgICAgIHJldHVybiB0aGlzLmVucXVldWUoInNldE9yaWVudGF0aW9uIiwgcHJvcGVydGllcyk7CiAgICB9OwoKICAgIE1NSW50ZXJzdGl0aWFsLnByb3RvdHlwZS5leHBhbmRUb0V4dGVybmFsQnJvd3NlciA9IGZ1bmN0aW9uKHVybCwgY2FsbGJhY2sp";
  private static final String MMJS_1_3_PART2 = "IHsKICAgICAgcmV0dXJuIHRoaXMuZW5xdWV1ZSgiZXhwYW5kVG9FeHRlcm5hbEJyb3dzZXIiLCB7CiAgICAgICAgdXJsOiB1cmwsCiAgICAgICAgY2FsbGJhY2s6IGNhbGxiYWNrCiAgICAgIH0pOwogICAgfTsKCiAgICBNTUludGVyc3RpdGlhbC5wcm90b3R5cGUuZXhwYW5kV2l0aFByb3BlcnRpZXMgPSBmdW5jdGlvbih1cmwsIHByb3BlcnRpZXMsIGNhbGxiYWNrKSB7CiAgICAgIHZhciBrZXksIHBhcmFtcywgdHJhbnNpdGlvblR5cGUsIHZhbHVlOwogICAgICBwYXJhbXMgPSB7CiAgICAgICAgY2FsbGJhY2s6IGNhbGxiYWNrCiAgICAgIH07CiAgICAgIGlmICh1cmwgIT0gbnVsbCkgewogICAgICAgIHBhcmFtc1sidXJsIl0gPSB1cmw7CiAgICAgIH0KICAgICAgTU1KUy51dGlscy5jb25zb2xlTG9nKCJleHBhbmRXaXRoUHJvcGVydGllcyBwcm9wZXJ0aWVzICIgKyBKU09OLnN0cmluZ2lmeShwcm9wZXJ0aWVzKSk7Ci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b3JjZU9yaWVudGF0aW9uOiAnbm9uZScKICAgICAgfTsKICAgICAgdGhpcy5yZXNpemVQcm9wZXJ0aWVzID0gewogICAgICAgIHdpZHRoOiBudWxsLAogICAgICAgIGhlaWdodDogbnVsbCwKICAgICAgICBjdXN0b21DbG9zZVBvc2l0aW9uOiAndG9wLXJpZ2h0JywKICAgICAgICBvZmZzZXRYOiAwLAogICAgICAgIG9mZnNldFk6IDAsCiAgICAgICAgYWxsb3dPZmZzY3JlZW46IHRydWUKICAgICAgfTsKICAgICAgdGhpcy5saXN0ZW5lcnMgPSB7fTsKICAgIH0KCiAgICBNUkFJRC5wcm90b3R5cGUuZ2V0QWRTaXplID0gZnVuY3Rpb24oKSB7CiAgICAgIGlmICh0aGlzLnNkay5hZFNpemUgIT0gbnVsbCkgewogICAgICAgIHRoaXMudXRpbHMuY29uc29sZUxvZygiTVJBSUQgZ2V0QWRTaXplICIgKyBKU09OLnN0cmluZ2lmeSh0aGlzLnNkay5hZFNpemUpKTsKICAgICAgICBpZiAodGhpcy5zZGsuYWRTaXplWyJoZWlnaHQiXSA+IDAgJiYgdGhpcy5zZGsuYWRTaXplWyJ3aWR0aCJdID4gMCkgewogICAgICAgICAgcmV0dXJuIHRoaXMuc2RrLmFkU2l6ZTsKICAgICAgICB9CiAgICAgIH0KICAgICAgcmV0dXJuIG51bGw7CiAgICB9OwoKICAgIE1SQUlELnByb3RvdHlwZS5jYWxsYmFja01hbmFnZXIgPSBmdW5jdGlvbihyZXNwb25zZSkgewogICAgICB2YXIga2xhc3MsIG1ldGhvZCwgcmVzcG9uc2VfZGF0YSwgcmVzdWx0OwogICAgICByZXN1bHQgPSByZXNwb25zZVsncmVzdWx0J107CiAgICAgIG1ldGhvZCA9IHJlc3BvbnNlWydjYWxsJ107CiAgICAgIHJlc3BvbnNlX2RhdGEgPSByZXNwb25zZVsncmVzcG9uc2UnXTsKICAgICAga2xhc3MgPSByZXNwb25zZVsnY2xhc3MnXTsKICAgICAgcmV0dXJuIHRoaXM7CiAgICB9OwoKICAgIE1SQUlELnByb3RvdHlwZS5nZXRWZXJzaW9uID0gZnVuY3Rpb24oKSB7CiAgICAgIHJldHVybiAiMi4wIjsKICAgIH07CgogICAgTVJBSUQucHJvdG90eXBlLmNsb3NlID0gZnVuY3Rpb24oKSB7CiAgICAgIHJldHVybiBNTUpTLmludGVyc3RpdGlhbC5jbG9zZSgoZnVuY3Rpb24ocmVzcG9uc2UpIHsKICAgICAgICBpZiAocmVzcG9uc2VbJ3Jlc3VsdCddIDwgMSkgewogICAgICAgICAgcmV0dXJuIG1yYWlkLmZpcmVFdmVudENhbGxiYWNrcygiZXJyb3IiLCAiQ2xvc2UgZmFpbGVkIiwgImNsb3NlIik7CiAgICAgICAgfQogICAgICB9KSk7CiAgICB9OwoKICAgIE1SQUlELnByb3RvdHlwZS5leHBhbmQgPSBmdW5jdGlvbihfdXJsKSB7CiAgICAgIHZhciBrLCBtYXhTaXplLCBwcm9wcywgdiwgX3JlZjsKICAgICAgdGhpcy51dGlscy5jb25zb2xlTG9nKCdtcmFpZC5leHBhbmQgY2FsbGVkIHdpdGggcHJvcGVydGllczogJyArIEpTT04uc3RyaW5naWZ5KHRoaXMuZ2V0RXhwYW5kUHJvcGVydGllcygpKSk7CiAgICAgIHRoaXMudXRpbHMuY29uc29sZUxvZygnbXJhaWQuZXhwYW5kIHVybDogJyArIF91cmwpOwogICAgICBwcm9wcyA9IHRoaXMuZ2V0RXhwYW5kUHJvcGVydGllcygpOwogICAgICBtYXhTaXplID0gdGhpcy5nZXRNYXhTaXplKCk7CiAgICAgIGlmICgocHJvcHMgIT0gbnVsbCkgJiYgKG1heFNpemUgIT0gbnVsbCkpIHsKICAgICAgICBpZiAocHJvcHNbImhlaWdodCJdID09PSBtYXhTaXplWyJoZWlnaHQiXSAmJiBwcm9wc1sid2lkdGgiXSA9PT0gbWF4U2l6ZVsid2lkdGgiXSkgewogICAgICAgICAgcHJvcHNbImhlaWdodCJdID0gdm9pZCAwOwogICAgICAgICAgcHJvcHNbIndpZHRoIl0gPSB2b2lkIDA7CiAgICAgICAgfQogICAgICB9CiAgICAgIF9yZWYgPSB0aGlzLm9yaWVudGF0aW9uUHJvcGVydGllczsKICAgICAgZm9yIChrIGluIF9yZWYpIHsKICAgICAgICB2ID0gX3JlZltrXTsKICAgICAgICBwcm9wc1trXSA9IHY7CiAgICAgIH0KICAgICAgcmV0dXJuIE1NSlMuaW50ZXJzdGl0aWFsLmV4cGFuZFdpdGhQcm9wZXJ0aWVzKF91cmwsIHByb3BzLCAoZnVuY3Rpb24ocmVzcG9uc2UpIHsKICAgICAgICBpZiAocmVzcG9uc2VbJ3Jlc3VsdCddIDwgMSkgewogICAgICAgICAgcmV0dXJuIG1yYWlkLmZpcmVFdmVudENhbGxiYWNrcygiZXJyb3IiLCAiRXhwYW5kIGZhaWxlZCIsICJleHBhbmQiKTsKICAgICAgICB9CiAgICAgIH0pKTsKICAgIH07CgogICAgTVJBSUQucHJvdG90eXBlLm9wZW4gPSBmdW5jdGlvbihfdXJsKSB7CiAgICAgIHJldHVybiBNTUpTLmludGVyc3RpdGlhbC5vcGVuKF91cmwsIChmdW5jdGlvbihyZXNwb25zZSkgewogICAgICAgIGlmIChyZXNwb25zZVsncmVzdWx0J10gPCAxKSB7CiAgICAgICAgICByZXR1cm4gbXJhaWQuZmlyZUV2ZW50Q2FsbGJhY2tzKCJlcnJvciIsICJPcGVuIGZhaWxlZCB0byBvcGVuIGV4dGVybmFsIHVybCIsICJvcGVuIik7CiAgICAgICAgfQogICAgICB9KSk7CiAgICB9OwoKICAgIE1SQUlELnByb3RvdHlwZS5nZXRFeHBhbmRQcm9wZXJ0aWVzID0gZnVuY3Rpb24oKSB7CiAgICAgIHZhciBtYXhTaXplOwogICAgICBtYXhTaXplID0gdGhpcy5nZXRNYXhTaXplKCk7CiAgICAgIGlmIChtYXhTaXplICE9IG51bGwpIHsKICAgICAgICBpZiAodGhpcy5wcm9wZXJ0aWVzWyJoZWlnaHQiXSA9PT0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iBmYWxzZTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHRoaXMudXRpbHMuY29uc29sZUxvZygiJyIgKyBldmVudCArICInIGZvdW5kIGxpc3RlbmVyOiAiICsgbGlzdGVuZXIpOwogICAgICAgICAgfQogICAgICAgICAgdGhpcy5saXN0ZW5lcnNbZXZlbnRdLnNwbGljZShpbmRleCwgMSk7CiAgICAgICAgICByZXR1cm4gdGhpcy51dGlscy5jb25zb2xlTG9nKCInIiArIGV2ZW50ICsgIicgbGlzdGVuZXJzOiAiICsgdGhpcy5saXN0ZW5lcnNbZXZlbnRdKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgcmV0dXJuIGRlbGV0ZSB0aGlzLmxpc3RlbmVyc1tldmVudF07CiAgICAgICAgfQogICAgICB9CiAgICB9OwoKICAgIE1SQUlELnByb3RvdHlwZS5hZGRFdmVudExpc3RlbmVyID0gZnVuY3Rpb24oZXZlbnQsIGxpc3RlbmVyKSB7CiAgICAgIGlmICghKHRoaXMubGlzdGVuZXJzW2V2ZW50XSAhPSBudWxsKSkgewogICAgICAgIHRoaXMubGlzdGVuZXJzW2V2ZW50XSA9IFtdOwogICAgICB9CiAgICAgIHRoaXMudXRpbHMuY29uc29sZUxvZygiJyIgKyBldmVudCArICInIGFkZGVkIGxpc3RlbmVyOiAiICsgbGlzdGVuZXIpOwogICAgICB0aGlzLmxpc3RlbmVyc1tldmVudF0ucHVzaChsaXN0ZW5lcik7CiAgICAgIHJldHVybiB0aGlzLnV0aWxzLmNvbnNvbGVMb2coIiciICsgZXZlbnQgKyAiJyBsaXN0ZW5lcnM6ICIgKyB0aGlzLmxpc3RlbmVyc1tldmVudF0pOwogICAgfTsKCiAgICBNUkFJRC5wcm90b3R5cGUuZmlyZUV2ZW50Q2FsbGJhY2tzID0gZnVuY3Rpb24oZXZlbnROYW1lLCBwYXJhbWV0ZXIsIGFjdGlvbikgewogICAgICB2YXIgY2FsbGJhY2ssIF9pLCBfbGVuLCBfcmV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SA9IGFkU2l6ZVsid2lkdGgiXTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHRoaXMucmVzaXplUHJvcGVydGllczsKICAgICAgfSBlbHNlIHsKICAgICAgICBNTUpTLnV0aWxzLmNvbnNvbGVMb2coImdldFJlc2l6ZVByb3BlcnRpZXMgZmFpbGVkIik7CiAgICAgICAgcmV0dXJuIG1yYWlkLmZpcmVFdmVudENhbGxiYWNrcygiZXJyb3IiLCAiZ2V0UmVzaXplUHJvcGVydGllcyBmYWlsZWQiLCAiZ2V0UmVzaXplUHJvcGVydGllcyIpOwogICAgICB9CiAgICB9OwoKICAgIE1SQUlELnByb3RvdHlwZS5zZXRSZXNpemVQcm9wZXJ0aWVzID0gZnVuY3Rpb24oX3Byb3BlcnRpZXMpIHsKICAgICAgcmV0dXJuIHRoaXMucmVzaXplUHJvcGVydGllcyA9IF9wcm9wZXJ0aWVzOwogICAgfTsKCiAgICBNUkFJRC5wcm90b3R5cGUuZ2V0Q3VycmVudFBvc2l0aW9uID0gZnVuY3Rpb24oKSB7CiAgICAgIHJldHVybiB0aGlzLnNkay5hZFNpemU7CiAgICB9OwoKICAgIE1SQUlELnByb3RvdHlwZS5nZXRNYXhTaXplID0gZnVuY3Rpb24oKSB7CiAgICAgIGlmICh0aGlzLnNkay5hZFByb3BlcnRpZXNbIm1heFNpemUiXSAhPSBudWxsKSB7CiAgICAgICAgcmV0dXJuIHsKICAgICAgICAgICJoZWlnaHQiOiB0aGlzLnNkay5hZFByb3BlcnRpZXNbIm1heFNpemUiXVsiaGVpZ2h0Il0sCiAgICAgICAgICAid2lkdGgiOiB0aGlzLnNkay5hZFByb3BlcnRpZXNbIm1heFNpemUiXVsid2lkdGgiXQogICAgICAgIH07CiAgICAgIH0gZWxzZSB7CiAgICAgICAgdGhpcy5maXJlRXZlbnRDYWxsYmFja3MoImVycm9yIiwgIm1heCBzaXplIGlzIHVuYXZhaWxhYmxlIiwgImdldE1heFNpemUiKTsKICAgICAgfQogICAgICByZX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OwogICAgICAgICAgTU1KUy51dGlscy5jb25zb2xlTG9nKCJydW5uaW5nIGNvbW1hbmQ6ICIgKyBjb21tYW5kLnVybCk7CiAgICAgICAgICB0cnkgewogICAgICAgICAgICByZXR1cm4gY29tbWFuZC5wZXJmb3JtKCk7CiAgICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICAgIHJldHVybiBNTUpTLnV0aWxzLmNvbnNvbGVMb2coIkZhaWxlZCB0byBydW4gY29tbWFuZDogIiArIGUubWVzc2FnZWFsZXJ0KTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgIH0sIDEpOwogIH0pKCkpOwp9Cg==";
  static final String MRAID_JS_FILE_NAME = "mraid.js";
  private static final String MRAID_JS_REPLACE_HEAD_PATTERN = "<head>";
  static final String MRAID_JS_REPLACE_IDENTIFIER = "<script src=\"mraid.js\"></script>";
  private static final String MRAID_JS_REPLACE_PATTERN = "<script.*src=[\"|']mraid\\.js[\"|']";
  private static final String ORIGINAL_MMJS_URL = "http://lp.mydas.mobi/assets/mmjs/1.3/mm.js";
  static final String STATE_DEFAULT = "default";
  static final String STATE_EXPANDED = "expanded";
  static final String STATE_HIDDEN = "hidden";
  static final String STATE_LOADING = "loading";

  static void downloadMraidJs(final Context paramContext, String paramString)
  {
    if (!TextUtils.isEmpty(paramString))
      Utils.ThreadUtils.execute(new Runnable()
      {
        // ERROR //
        public void run()
        {
          // Byte code:
          //   0: new 33	org/apache/http/client/methods/HttpGet
          //   3: dup
          //   4: aload_0
          //   5: getfield 19	com/millennialmedia/android/MRaid$1:val$url	Ljava/lang/String;
          //   8: invokespecial 36	org/apache/http/client/methods/HttpGet:<init>	(Ljava/lang/String;)V
          //   11: astore_1
          //   12: new 38	org/apache/http/impl/client/DefaultHttpClient
          //   15: dup
          //   16: invokespecial 39	org/apache/http/impl/client/DefaultHttpClient:<init>	()V
          //   19: aload_1
          //   20: invokevirtual 43	org/apache/http/impl/client/DefaultHttpClient:execute	(Lorg/apache/http/client/methods/HttpUriRequest;)Lorg/apache/http/HttpResponse;
          //   23: astore 6
          //   25: aload_0
          //   26: getfield 21	com/millennialmedia/android/MRaid$1:val$context	Landroid/content/Context;
          //   29: aload 6
          //   31: invokeinterface 49 1 0
          //   36: invokeinterface 55 1 0
          //   41: invokestatic 59	com/millennialmedia/android/MRaid:saveMRaid	(Landroid/content/Context;Ljava/io/InputStream;)Z
          //   44: ifeq +14 -> 58
          //   47: aload_0
          //   48: getfield 21	com/millennialmedia/android/MRaid$1:val$context	Landroid/content/Context;
          //   51: aload_0
          //   52: getfield 19	com/millennialmedia/android/MRaid$1:val$url	Ljava/lang/String;
          //   55: invokestatic 62	com/millennialmedia/android/MRaid:storeMraidUrl	(Landroid/content/Context;Ljava/lang/String;)V
          //   58: return
          //   59: astore 5
          //   61: aload 5
          //   63: invokevirtual 65	java/net/MalformedURLException:printStackTrace	()V
          //   66: return
          //   67: astore_3
          //   68: aload_3
          //   69: athrow
          //   70: astore 4
          //   72: aload 4
          //   74: invokevirtual 66	java/lang/IllegalStateException:printStackTrace	()V
          //   77: return
          //   78: astore_2
          //   79: aload_2
          //   80: invokevirtual 67	java/io/IOException:printStackTrace	()V
          //   83: return
          //
          // Exception table:
          //   from	to	target	type
          //   0	58	59	java/net/MalformedURLException
          //   0	58	67	finally
          //   61	66	67	finally
          //   72	77	67	finally
          //   79	83	67	finally
          //   0	58	70	java/lang/IllegalStateException
          //   0	58	78	java/io/IOException
        }
      });
  }

  // ERROR //
  static String getMMJSStats(Context paramContext)
  {
    // Byte code:
    //   0: aload_0
    //   1: invokestatic 71	com/millennialmedia/android/MRaid:hasMraidLocally	(Landroid/content/Context;)Z
    //   4: ifne +6 -> 10
    //   7: ldc 73
    //   9: areturn
    //   10: aload_0
    //   11: invokestatic 77	com/millennialmedia/android/MRaid:getMRaidJsFile	(Landroid/content/Context;)Ljava/io/File;
    //   14: astore_1
    //   15: aconst_null
    //   16: astore_2
    //   17: ldc 79
    //   19: astore_3
    //   20: new 81	java/io/FileInputStream
    //   23: dup
    //   24: aload_1
    //   25: invokespecial 84	java/io/FileInputStream:<init>	(Ljava/io/File;)V
    //   28: astore 4
    //   30: aload_1
    //   31: invokevirtual 90	java/io/File:length	()J
    //   34: l2i
    //   35: newarray byte
    //   37: astore 11
    //   39: aload 4
    //   41: aload 11
    //   43: invokevirtual 94	java/io/FileInputStream:read	([B)I
    //   46: pop
    //   47: ldc 96
    //   49: invokestatic 102	java/security/MessageDigest:getInstance	(Ljava/lang/String;)Ljava/security/MessageDigest;
    //   52: aload 11
    //   54: invokevirtual 106	java/security/MessageDigest:digest	([B)[B
    //   57: invokestatic 112	com/millennialmedia/android/MMSDK:byteArrayToString	([B)Ljava/lang/String;
    //   60: astore 13
    //   62: aload 13
    //   64: astore_3
    //   65: aload 4
    //   67: ifnull +8 -> 75
    //   70: aload 4
    //   72: invokevirtual 115	java/io/FileInputStream:close	()V
    //   75: new 117	java/util/Date
    //   78: dup
    //   79: aload_1
    //   80: invokevirtual 120	java/io/File:lastModified	()J
    //   83: invokespecial 123	java/util/Date:<init>	(J)V
    //   86: astore 7
    //   88: iconst_4
    //   89: anewarray 4	java/lang/Object
    //   92: astore 8
    //   94: aload 8
    //   96: iconst_0
    //   97: aload_3
    //   98: aastore
    //   99: aload 8
    //   101: iconst_1
    //   102: aload 7
    //   104: aastore
    //   105: aload 8
    //   107: iconst_2
    //   108: aload_1
    //   109: invokevirtual 90	java/io/File:length	()J
    //   112: invokestatic 129	java/lang/Long:valueOf	(J)Ljava/lang/Long;
    //   115: aastore
    //   116: aload 8
    //   118: iconst_3
    //   119: aload_0
    //   120: invokestatic 135	com/millennialmedia/android/HandShake:sharedHandShake	(Landroid/content/Context;)Lcom/millennialmedia/android/HandShake;
    //   123: getfield 138	com/millennialmedia/android/HandShake:mmjsUrl	Ljava/lang/String;
    //   126: aastore
    //   127: ldc 140
    //   129: aload 8
    //   131: invokestatic 146	java/lang/String:format	(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;
    //   134: areturn
    //   135: astore 14
    //   137: goto -62 -> 75
    //   140: astore 15
    //   142: aload_2
    //   143: ifnull -68 -> 75
    //   146: aload_2
    //   147: invokevirtual 115	java/io/FileInputStream:close	()V
    //   150: goto -75 -> 75
    //   153: astore 6
    //   155: goto -80 -> 75
    //   158: astore 9
    //   160: aload_2
    //   161: ifnull +7 -> 168
    //   164: aload_2
    //   165: invokevirtual 115	java/io/FileInputStream:close	()V
    //   168: aload 9
    //   170: athrow
    //   171: astore 10
    //   173: goto -5 -> 168
    //   176: astore 9
    //   178: aload 4
    //   180: astore_2
    //   181: goto -21 -> 160
    //   184: astore 5
    //   186: aload 4
    //   188: astore_2
    //   189: goto -47 -> 142
    //
    // Exception table:
    //   from	to	target	type
    //   70	75	135	java/lang/Exception
    //   20	30	140	java/lang/Exception
    //   146	150	153	java/lang/Exception
    //   20	30	158	finally
    //   164	168	171	java/lang/Exception
    //   30	62	176	finally
    //   30	62	184	java/lang/Exception
  }

  private static File getMRaidJsFile(Context paramContext)
  {
    return new File(AdCache.getCacheDirectory(paramContext), "mraid.js");
  }

  static String getMRaidJsPath(Context paramContext)
  {
    return Uri.fromFile(getMRaidJsFile(paramContext)).toString();
  }

  static boolean hasMraidLocally(Context paramContext)
  {
    File localFile = getMRaidJsFile(paramContext);
    return (localFile != null) && (localFile.exists());
  }

  static String injectMraidJs(Context paramContext, String paramString)
  {
    Matcher localMatcher1 = Pattern.compile("<script.*src=[\"|']mraid\\.js[\"|']").matcher(paramString);
    String str = getMRaidJsPath(paramContext);
    MMSDK.Log.d("Mraid path: " + getMRaidJsPath(paramContext));
    if (localMatcher1.find())
      paramString = localMatcher1.replaceFirst("<script src=\"" + str + "\"");
    while (true)
    {
      if (paramString.indexOf("<html>") == -1)
        paramString = "<html><head></head><body style='margin:0;padding:0;'>" + paramString + "</body></html>";
      return paramString;
      if (paramString.indexOf("<head>") == -1)
      {
        paramString = "<script src=\"" + str + "\"></script>" + paramString;
      }
      else
      {
        Matcher localMatcher2 = Pattern.compile("<head>").matcher(paramString);
        if (localMatcher2.find())
          paramString = localMatcher2.replaceFirst("<head><script src=\"" + str + "\"></script>");
      }
    }
  }

  static boolean isMRaidAd(String paramString)
  {
    if (paramString == null)
      return false;
    return Pattern.compile("<script.*src=[\"|']mraid\\.js[\"|']").matcher(paramString).find();
  }

  static boolean isMRaidUpdated(Context paramContext, String paramString)
  {
    boolean bool = hasMraidLocally(paramContext);
    if ((!bool) && ("http://lp.mydas.mobi/assets/mmjs/1.3/mm.js".equals(paramString)))
      saveIncludedMMJS(paramContext, paramString);
    while (true)
    {
      return true;
      String str = paramContext.getSharedPreferences("MillennialMediaSettings", 0).getString("KEY_MMJS_URL", "");
      if ((!TextUtils.isEmpty(str)) && (str.equals(paramString)));
      for (int i = 1; (i == 0) || (!bool); i = 0)
        return false;
    }
  }

  static boolean saveIncludedMMJS(Context paramContext, String paramString)
  {
    byte[] arrayOfByte1 = Base64.decode("LyoqCiogTWlsbGVubmlhbCBNZWRpYSBKUyBMaWJyYXJ5IChNTS5qcykKKiBDb3B5cmlnaHQgMjAxMC0yMDEzLCBNaWxsZW5uaWFsIE1lZGlhCioKKiBCdWlsdCBvbiBUaHUgQXByIDA0IDIwMTMgMTE6MDk6MTEgR01ULTA3MDAgKFBEVCkuCiovCgovLyBHZW5lcmF0ZWQgYnkgQ29mZmVlU2NyaXB0IDEuMy4zCnZhciBNTUFwcFN0b3JlLCBNTUJhbm5lciwgTU1CcmFuZCwgTU1CcmlkZ2VPYmplY3QsIE1NQ2FjaGVkVmlkZW8sIE1NQ2FsZW5kYXIsIE1NQ29tbWFuZCwgTU1EZXZpY2UsIE1NRmlsZU1hbmFnZXIsIE1NSW5saW5lVmlkZW8sIE1NSW50ZXJzdGl0aWFsLCBNTUpTLCBNTUpTVXRpbHMsIE1NTWVkaWEsIE1NTm90aWZpY2F0aW9uLCBNTVBhc3Nib29rLCBNTVBhc3RlYm9hcmQsIE1NU0RLSW50ZXJmYWNlLCBNTVNvY2lhb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IG51bGw7CgogICAgTU1KU1V0aWxzLnBhcmFtcyA9IG51bGw7CgogICAgTU1KU1V0aWxzLmlzQnJpZGdlRW5hYmxlZCA9IGZ1bmN0aW9uKCkgewogICAgICBpZiAoTU1EZXZpY2UucmVhZHlTdGF0ZSAhPT0gInVua25vd24iKSB7CiAgICAgICAgcmV0dXJuIHRydWU7CiAgICAgIH0KICAgICAgcmV0dXJuIGZhbHNlOwogICAgfTsKCiAgICBNTUpTVXRpbHMuaXNQcmU0NiA9IGZ1bmN0aW9uKGEpIHsKICAgICAgaWYgKHRoaXMuaXNCcmlkZ2VFbmFibGVkKCkgPT09IHRydWUpIHsKICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgIH0KICAgICAgaWYgKGEgPT0gbnVsbCkgewogICAgICAgIHJldHVybiB0cnVlOwogICAgICB9CiAgICAgIHJldHVybiB0aGlzLnVuZGVyVmVyc2lvbihhLCAiNC42LjAiKTsKICAgIH07CgogICAgTU1KU1V0aWxzLnVuZGVyVmVyc2lvbiA9IGZ1bmN0aW9uKHZlcnNpb25TdHJpbmcsIG1pblZlcnNpb24pIHsKICAgICAgdmFyIGksIHJlcywgcmVzdWx0LCB2MSwgdjI7CiAgICAgIGlmICh2ZXJzaW9uU3RyaW5nID09IG51bGwpIHsKICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgIH0KICAgICAgdjEgPSB2ZXJzaW9uU3RyaW5nLnNwbGl0KCIuIik7CiAgICAgIHYyID0gbWluVmVyc2lvbi5zcGxpdCgiLiIpOwogICAgICBpID0gMDsKICAgICAgcmVzdWx0ID0gMDsKICAgICAgd2hpbGUgKGkgPCBNYXRoLm1pbih2MS5sZW5ndGgsIHYyLmxlbmd0aCkpIHsKICAgICAgICByZXMgPSB2MVtpXSAtIHYyW2ldOwogICAgICAgIGlmIChyZXMgIT09IDApIHsKICAgICAgICAgIHJlc3VsdCA9IHJlczsKICAgICAgICAgIGJyZWFrOwogICAgICAgIH0KICAgICAgICBpKys7CiAgICAg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BsaXQoJy0nKTsKICAgICAgICB0aGlzLnNka192ZXJzaW9uID0gbW1pc2RrWzBdOwogICAgICAgIHJldHVybiB0aGlzLnNka192ZXJzaW9uOwogICAgICB9CiAgICAgIHJldHVybiBudWxsOwogICAgfTsKCiAgICBNTUpTVXRpbHMuc2ltdWxhdGVSZWRpcmVjdCA9IGZ1bmN0aW9uKHVybCkgewogICAgICB2YXIgZXZlbnRGaXJlLCBsaW5rVGFnOwogICAgICBsaW5rVGFnID0gZG9jdW1lbnQuY3JlYXRlRWxlbWVudCgiYSIpOwogICAgICBsaW5rVGFnLmlkID0gIm1tX3NpbXVsYXRlTGluayI7CiAgICAgIGxpbmtUYWcuc2V0QXR0cmlidXRlKCJocmVmIiwgdXJsKTsKICAgICAgbGlua1RhZy5zZXRBdHRyaWJ1dGUoInN0eWxlIiwgIm9wYWNpdHk6MCIpOwogICAgICBkb2N1bWVudC5ib2R5LmFwcGVuZENoaWxkKGxpbmtUYWcpOwogICAgICBldmVudEZpcmUgPSBmdW5jdGlvbihlbCwgZXR5cGUpIHsKICAgICAgICB2YXIgZXZPYmo7CiAgICAgICAgaWYgKGVsLmZpcmVFdmVudCkgewogICAgICAgICAgcmV0dXJuIGVsLmZpcmVFdmVudCgib24iICsgZXR5cGUpOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBldk9iaiA9IGRvY3VtZW50LmNyZWF0ZUV2ZW50KCJFdmVudHMiKTsKICAgICAgICAgIGV2T2JqLmluaXRFdmVudChldHlwZSwgdHJ1ZSwgZmFsc2UpOwogICAgICAgICAgcmV0dXJuIGVsLmRpc3BhdGNoRXZlbnQoZXZPYmopOwogICAgICAgIH0KICAgICAgfTsKICAgICAgcmV0dXJuIHdpbmRvdy5zZXRUaW1lb3V0KChmdW5jdGlvbigpIHsKICAgICAgICB2YXIgZWxlbWVudDsKICAgICAgICBlbGVtZW50ID0gbGlua1RhZzsKICAgICAgICByZXR1cm4gZXZlbnRGaXJlKGxpbmtUYWcsICJjbGljayIpOwogICAgICB9KSwgMSk7CiAgICB9OwoKICAgIE1NSlNVdGlscy5tb2REdXJhdGlvbiA9IGZ1bmN0aW9uKGR1cmF0aW9uKSB7CiAgICAgIGlmICghdGhpcy5pc0FuZHJvaWQoKSkgewogICAgICAgIHJldHVybiBkdXJhdGlvbjsKICAgICAgfQogICAgICBpZiAoZHVyYXRpb24gPCAxMDApIHsKICAgICAgICByZXR1cm4gZHVyYXRpb24gKiAxMDAwOwogICAgICB9IGVsc2UgewogICAgICAgIHJldHVybiBkdXJhdGlvbjsKICAgICAgfQogICAgfTsKCiAgICBNTUpTVXRpbHMuZ2V0UGFyYW1zID0gZnVuY3Rpb24oKSB7CiAgICAgIHZhciBuLCBuYW1lLCBwYWlyLCBwYXJhbXMsIHFzLCB2YWx1ZSwgX2ksIF9sZW4sIF9yZWYsIF9yZWYxOwogICAgICBpZiAodGhpcy5wYXJhbXMgIT0gbnVsbCkgewogICAgICAgIHJldHVybiB0aGlzLnBhcmFtczsKICAgICAgfQogICAgICBwYXJhbXMgPSB7fTsKICAgICAgcXMgPSB3aW5kb3cubG9jYXRpb24uc2VhcmNoLnN1YnN0cmluZygxKTsKICAgICAgaWYgKHFzLmxlbmd0aCkgewogICAgICAgIF9yZWYgPSAoZnVuY3Rpb24oKSB7CiAgICAgICAgICB2YXIgX2osIF9sZW4sIF9yZWYsIF9yZXN1bHRzOwogICAgICAgICAgX3JlZiA9IHFzLnNwbGl0KCcmJyk7CiAgICAgICAgICBfcmVzdWx0cyA9IFtdOwogICAgICAgICAgZm9yIChfaiA9IDAsIF9sZW4gPSBfcmVmLmxlbmd0aDsgX2ogPCBfbGVuOyBfaisrKSB7CiAgICAgICAgICAgIHBhaXIgPSBfcmVmW19qXTsKICAgICAgICAgICAgX3Jlc3VsdHMucHVzaChwYWlyLnNwbGl0KCc9JykpOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIF9yZXN1bHRzOwogICAgICAgIH0pKCk7CiAgICAgICAgZm9yIChfaSA9IDAsIF9sZW4gPSBfcmVmLmxlbmd0aDsgX2kgPCBfbGVuOyBfaSsrKSB7CiAgICAgICAgICBfcmVmMSA9IF9yZWZbX2ldLCBuYW1lID0gX3JlZjFbMF0sIHZhbHVlID0gX3JlZjFbMV07CiAgICAgICAgICBuID0gbmFtZS5yZXBsYWNlKCJtbV8iLCAiIik7CiAgICAgICAgICBpZiAodmFsdWUgIT0gbnVsbCkgewogICAgICAgICAgICBwYXJhbXNbbl0gPSB2YWx1ZTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgdGhpcy5wYXJhbXMgPSBwYXJhbXM7CiAgICAgIHJldHVybiB0aGlzLnBhcmFtczsKICAgIH07CgogICAgTU1KU1V0aWxzLmNvbnNvbGVMb2cgPSBmdW5jdGlvbihfbXNnLCBfdXNlQWxlcnQpIHsKICAgICAgaWYgKF91c2VBbGVydCA9PSBudWxsKSB7CiAgICAgICAgX3VzZUFsZXJ0ID0gZmFsc2U7CiAgICAgIH0KICAgICAgTU1KUy5ldmVudFRyYWNraW5nLnB1c2goX21zZyk7CiAgICAgIGlmICh0aGlzLmlzQW5kcm9pZCgpKSB7CiAgICAgICAgaWYgKHdpbmRvdy5jb25zb2xlICE9IG51bGwpIHsKICAgICAgICAgIHdpbmRvdy5jb25zb2xlLmxvZyhfbXNnKTsKICAgICAgICB9CiAgICAgIH0gZWxzZSBpZiAodGhpcy5pc1dpbmRvd3MoKSkgewogICAgICAgIHdpbmRvdy5leHRlcm5hbC5ub3RpZnkoX21zZyk7CiAgICAgIH0gZWxzZSB7CiAgICAgICAgaWYgKHdpbmRvdy5jb25zb2xlICE9IG51bGwpIHsKICAgICAgICAgIHdpbmRvdy5jb25zb2xlLmxvZyhfbXNnKTsKICAgICAgICB9CiAgICAgICAgaWYgKF91c2VBbGVydCkgewogICAgICAgICAgYWxlcnQoX21zZyk7CiAgICAgICAgfQogICAgICB9CiAgICAgIHJldHVybiBmYWxzZTsKICAgIH07CgogICAgTU1KU1V0aWxzLmlPU1ZlcnNpb24gPSBmdW5jdGlvbigpIHsKICAgICAgdmFyIF92OwogICAgICBpZiAodGhpcy5pb3NfdmVyc2lvbikgewogICAgICAgIHJldHVybiB0aGlzLmlvc192ZXJzaW9uOwogICAgICB9CiAgICAgIF92ID0gbmF2aWdhdG9yLmFwcFZlcnNpb24uc3BsaXQoJyBPUyAnKVsxXTsKICAgICAgX3YgPSBfdi5zcGxpdCgnICcpWzBdLnRyaW0oKS5zcGxpdCgnXycpOwogICAgICBfdi5zcGxpY2UoMSwgMCwgJy4nKTsKICAgICAgcmV0dXJuIHRoaXMuaW9zX3ZlcnNpb24gPSBwYXJzZUZsb2F0KF92LmpvaW4oJycpKTsKICAgIH07CgogICAgTU1KU1V0aWxzLmdldExvY2F0aW9uID0gZnVuY3Rpb24oZnVuYywgZXJyb3IpIHsKICAgICAgaWYgKG5hdmlnYXRvci5nZW9sb2NhdGlvbikgewogICAgICAgIHJldHVybiBuYXZpZ2F0b3IuZ2VvbG9jYXRpb24uZ2V0Q3VycmVudFBvc2l0aW9uKGZ1bmMsIGVycm9yLCB7CiAgICAgICAgICBlbmFibGVIaWdoQWNjdXJhY3k6IHRydWUKICAgICAgICB9KTsKICAgICAgfSBlbHNlIHsKICAgICAgICByZXR1cm4gZXJyb3IoewogICAgICAgICAgY29kZTogOTkKICAgICAgICB9KTsKICAgICAgfQogICAgfTsKCiAgICBNTUpTVXRpbHMubGlzdGVuRm9yQnJvd3NlclJlYWR5ID0gZnVuY3Rpb24oZnVuYykgewogICAgICBpZiAodGhpcy5pc1dpbmRvd3MoKSkgewogICAgICAgIHJldHVybiBkb2N1bWVudC5hdHRhY2hFdmVudCgib25yZWFkeXN0YXRlY2hhbmdlIiwgZnVuYyk7CiAgICAgIH0gZWxzZSB7CiAgICAgICAgcmV0dXJuIGRvY3VtZW50LmFkZEV2ZW50TGlzdGVuZXIoIkRPTUNvbnRlbnRMb2FkZWQiLCBmdW5jLCBmYWxzZSk7CiAgICAgIH0KICAgI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zLm9wZW4odXJsLCBwYXJhbXMsIGZhbHNlKTsKICAgIH07CgogICAgTU1KUy5vcGVuID0gZnVuY3Rpb24odXJsLCBwYXJhbXMsIGF1dG9FeHBhbmQpIHsKICAgICAgaWYgKHBhcmFtcyA9PSBudWxsKSB7CiAgICAgICAgcGFyYW1zID0ge307CiAgICAgIH0KICAgICAgaWYgKGF1dG9FeHBhbmQgPT0gbnVsbCkgewogICAgICAgIGF1dG9FeHBhbmQgPSB0cnVlOwogICAgICB9CiAgICAgIG1yYWlkLnNldEV4cGFuZFByb3BlcnRpZXMocGFyYW1zKTsKICAgICAgcmV0dXJuIG1yYWlkLmV4cGFuZCh1cmwpOwogICAgfTsKCiAgICBNTUpTLmNsb3NlID0gZnVuY3Rpb24oZHVyYXRpb24pIHsKICAgICAgdmFyIG1vZER1cmF0aW9uOwogICAgICBpZiAoZHVyYXRpb24gPT0gbnVsbCkgewogICAgICAgIGR1cmF0aW9uID0gMDsKICAgICAgfQogICAgICBtb2REdXJhdGlvbiA9IGZ1bmN0aW9uKGR1cmF0aW9uKSB7CiAgICAgICAgaWYgKGR1cmF0aW9uIDwgMTAwKSB7CiAgICAgICAgICByZXR1cm4gZHVyYXRpb24gKiAxMDAwOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICByZXR1cm4gZHVyYXRpb247CiAgICAgICAgfQogICAgICB9OwogICAgICByZXR1cm4gc2V0VGltZW91dChmdW5jdGlvbigpIHsKICAgICAgICByZXR1cm4gTU1KUy5pbnRlcnN0aXRpYWwuY2xvc2UoKTsKICAgICAgfSwgbW9kRHVyYXRpb24oZHVyYXRpb24pKTsKICAgIH07CgogICAgTU1KUy5vcGVuRXh0ZXJuYWwgPSBmdW5jdGlvbih1cmwpIHsKICAgICAgaWYgKHRoaXMudXRpbHMuaXNCcmlkZ2VFbmFibGVkKCkpIHsKICAgICAgICByZXR1cm4gTU1EZXZpY2Uub3BlblVybCh1cmwpOwogICAgICB9IGVsc2UgewogICAgICAgIGlmICh0aG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AgICAgICAgfQogICAgICAgICAgICBuYW1lc3BhY2VzID0gZnVuYy5zcGxpdCgiLiIpOwogICAgICAgICAgICBhRnVuYyA9IG5hbWVzcGFjZXMucG9wKCk7CiAgICAgICAgICAgIGkgPSAwOwogICAgICAgICAgICBjb250ZXh0ID0gd2luZG93OwogICAgICAgICAgICB3aGlsZSAoaSA8IG5hbWVzcGFjZXMubGVuZ3RoKSB7CiAgICAgICAgICAgICAgTU1KUy51dGlscy5jb25zb2xlTG9nKCJuYW1lc3BhY2U6ICIgKyBuYW1lc3BhY2VzW2ldKTsKICAgICAgICAgICAgICBjb250ZXh0ID0gY29udGV4dFtuYW1lc3BhY2VzW2ldXTsKICAgICAgICAgICAgICBpKys7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgTU1KUy51dGlscy5jb25zb2xlTG9nKCJhRnVuYzogIiArIGFGdW5jKTsKICAgICAgICAgICAgTU1KUy51dGlscy5jb25zb2xlTG9nKCJjb250ZXh0OiAiICsgY29udGV4dCk7CiAgICAgICAgICAgIGNvbnRleHRbYUZ1bmNdKHJlc3BvbnNlKTsKICAgICAgICAgICAgcmV0dXJuIE1NSlMuc2V0RXhlY3V0aW5nQ29tbWFuZChmYWxzZSk7CiAgICAgICAgICB9OwogICAgICAgIH0gZWxzZSBpZiAodHlwZW9mIGZ1bmMgPT09IE1NSlMuVFlQRV9GVU5DVElPTikgewogICAgICAgICAgd2luZG93WyJNTUpTIl1bImNhbGxiYWNrcyJdW2Z1bmN0aW9uTmFtZV0gPSBmdW5jdGlvbihyZXNwb25zZSkgewogICAgICAgICAgICBpZiAocmVzcG9uc2UgIT0gbnVsbCkgewogICAgICAgICAgICAgIHJlc3BvbnNlWydkYXRhJ10gPSByZXNwb25zZVsncmVzcG9uc2UnXTsKICAgICAgICAgICAgICByZXNwb25zZVsncmVzdWx0J10gPSBwYXJzZUludChyZXNwb25zZVsncmVzdWx0J10pOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGZ1bmMocmVzcG9uc2UpOwogICAgICAgICAgICByZXR1cm4gTU1KUy5zZXRFeGVjdXRpbmdDb21tYW5kKGZhbHNlKTsKICAgICAgICAgIH07CiAgICAgICAgfSBlbHNlIGlmICh0eXBlb2YgZnVuYyA9PT0gTU1KUy5UWVBFX1VOREVGSU5FRCkgewogICAgICAgICAgd2luZG93WyJNTUpTIl1bImNhbGxiYWNrcyJdW2Z1bmN0aW9uTmFtZV0gPSBmdW5jdGlvbihyZXNwb25zZSkgewogICAgICAgICAgICBNTUpTLnV0aWxzLmNvbnNvbGVMb2coImV4ZWN1dGluZyB1bmRlZmluZWQgY2FsbGJhY2s6ICIgKyBmdW5jdGlvbk5hbWUpOwogICAgICAgICAgICBNTUpTLnV0aWxzLmNvbnNvbGVMb2coIm5vIGNhbGxiYWNrIHdhcyBzcGVjaWZpZWQiKTsKICAgICAgICAgICAgcmV0dXJuIE1NSlMuc2V0RXhlY3V0aW5nQ29tbWFuZChmYWxzZSk7CiAgICAgICAgICB9OwogICAgICAgIH0KICAgICAgICBwYXJhbXNbImNhbGxiYWNrIl0gPSAiTU1KUy5jYWxsYmFja3MuIiArIGZ1bmN0aW9uTmFtZTsKICAgICAgICB0aGlzLmNhbGxiYWNrID0gcGFyYW1zWyJjYWxsYmFjayJdOwogICAgICAgIGZvciAobmFtZSBpbiBwYXJhbXMpIHsKICAgICAgICAgIGlmICh0eXBlb2YgbmFtZSAhPT0gTU1KUy5UWVBFX1NUUklORykgewogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChwYXJhbXNbbmFtZV0gPT09IHZvaWQgMCB8fCBwYXJhbXNbbmFtZV0gPT09IG51bGwpIHsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBxdWVyeV9hcmdzLnB1c2goZW5jb2RlVVJJQ29tcG9uZW50KG5hbWUpICsgIj0iICsgZW5jb2RlVVJJQ29tcG9uZW50KHBhcmFtc1tuYW1lXSkpOwogICAg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ldHVybiB0aGlzLmVucXVldWUoImdldEF2YWlsYWJsZVNjaGVtZXMiLCB7CiAgICAgICAgY2FsbGJhY2s6IGNhbGxiYWNrCiAgICAgIH0pOwogICAgfTsKCiAgICBNTURldmljZS5wcm90b3R5cGUuaXNTY2hlbWVBdmFpbGFibGUgPSBmdW5jdGlvbihzY2hlbWUsIGNhbGxiYWNrKSB7CiAgICAgIHJldHVybiB0aGlzLmVucXVldWUoImlzU2NoZW1lQXZhaWxhYmxlIiwgewogICAgICAgIHNjaGVtZTogc2NoZW1lLAogICAgICAgIGNhbGxiYWNrOiBjYWxsYmFjawogICAgICB9KTsKICAgIH07CgogICAgTU1EZXZpY2UucHJvdG90eXBlLmdldEF2YWlsYWJsZVNjaGVtZXMgPSBmdW5jdGlvbihjYWxsYmFjaykgewogICAgICByZXR1cm4gdGhpcy5lbnF1ZXVlKCJnZXRBdmFpbGFibGVTY2hlbWVzIiwgewogICAgICAgIGNhbGxiYWNrOiBjYWxsYmFjawogICAgICB9KTsKICAgIH07CgogICAgTU1EZXZpY2UucHJvdG90eXBlLmdldE9yaWVudGF0aW9uID0gZnVuY3Rpb24oY2FsbGJhY2spIHsKICAgICAgcmV0dXJuIHRoaXMuZW5xdWV1ZSgiZ2V0T3JpZW50YXRpb24iLCB7CiAgICAgICAgY2FsbGJhY2s6IGNhbGxiYWNrCiAgICAgIH0pOwogICAgfTsKCiAgICBNTURldmljZS5wcm90b3R5cGUuZ2V0TG9jYXRpb24gPSBmdW5jdGlvbihjYWxsYmFjaykgewogICAgICByZXR1cm4gdGhpcy5lbnF1ZXVlKCJnZXRMb2NhdGlvbiIsIHsKICAgICAgICBjYWxsYmFjazogY2FsbGJhY2sKICAgICAgfSk7CiAgICB9OwoKICAgIE1NRGV2aWNlLnByb3RvdHlwZS5zaG93TWFwID0gZnVuY3Rpb24obG9jYXRpb24sIGNhbGxiYWNrKSB7CiAgICAgIHJldHVybiB0aGlzLmVucXVldWUoInNob3dNYXAiLCB7CiAgICAgICAgbG9jYXRpb246IGxvY2F0aW9uLAogICAgICAgIGNhbGxiYWNrOiBjYWxsYmFjawogICAgICB9KTsKICAgIH07CgogICAgTU1EZXZpY2UucHJvdG90eXBlLmNhbGwgPSBmdW5jdGlvbihudW1iZXIsIGRpYWwsIGNhbGxiYWNrKSB7CiAgICAgIHJldHVybiB0aGlzLmVucXVldWUoImNhbGwiLCB7CiAgICAgICAgbnVtYmVyOiBudW1iZXIsCiAgICAgICAgY2FsbGJhY2s6IGNhbGxiYWNrLAogICAgICAgIGRpYWw6IGRpYWwKICAgICAgfSk7CiAgICB9OwoKICAgIE1NRGV2aWNlLnByb3RvdHlwZS5vcGVuVXJsID0gZnVuY3Rpb24odXJsLCBjYWxsYmFjaykgewogICAgICByZXR1cm4gdGhpcy5lbnF1ZXVlKCJvcGVuVXJsIiwgewogICAgICAgIHVybDogdXJsLAogICAgICAgIGNhbGxiYWNrOiBjYWxsYmFjawogICAgICB9KTsKICAgIH07CgogICAgTU1EZXZpY2UucHJvdG90eXBlLm9wZW5BcHBTdG9yZSA9IGZ1bmN0aW9uKGFwcElkLCBjYWxsYmFjaykgewogICAgICByZXR1cm4gdGhpcy5lbnF1ZXVlKCJvcGVuQXBwU3RvcmUiLCB7CiAgICAgICAgYXBwSWQ6IGFwcElkLAogICAgICAgIGNhbGxiYWNrOiBjYWxsYmFjawogICAgICB9KTsKICAgIH07CgogICAgTU1EZXZpY2UucHJvdG90eXBlLmNvbXBvc2VTTVMgPSBmdW5jdGlvbihudW1iZXIsIG1lc3NhZ2UsIGNhbGxiYWNrKSB7CiAgICAgIHJldHVybiB0aGlzLmNvbXBvc2VTbXMobnVtYmVyLCBtZXNzYWdlLCBjYWxsYmFjayk7CiAgICB9OwoKICAgIE1NRGV2aWNlLnByb3RvdHlwZS5jb21wb3NlU21zID0gZnVuY3Rpb24obnVtYmVyLCBtZXNzYWdlLCBjYWxsYmFjaykgewogICAgICBpZiAodGhpcy51dGlscy5pc0lPUygpKSB7CiAgICAgICAgcmV0dXJuIHRoaXMuZW5xdWV1ZSgiY29tcG9zZVNtcyIsIHsKICAgICAgICAgIG51bWJlcjogbnVtYmVyLAogICAgICAgICAgbWVzc2FnZTogbWVzc2FnZSwKICAgICAgICAgIGNhbGxiYWNrOiBjYWxsYmFjawogICAgICAgIH0pOwogICAgICB9IGVsc2UgewogICAgICAgIHJldHVybiB0aGlzLmVucXVldWUoImNvbXBvc2VTbXMiLCB7CiAgICAgICAgICBudW1iZXI6IG51bWJlciwKICAgICAgICAgIG1lc3NhZ2U6IG1lc3NhZ2UsCiAgICAgICAgICBjYWxsYmFjazogY2FsbGJhY2sKICAgICAgICB9KTsKICAgICAgfQogICAgfTsKCiAgICBNTURldmljZS5wcm90b3R5cGUuY29tcG9zZUVtYWlsID0gZnVuY3Rpb24ocmVjaXBpZW50LCBzdWJqZWN0LCBtZXNzYWdlLCBjYWxsYmFjaykgewogICAgICBpZiAodGhpcy51dGlscy5pc0lPUygpKSB7CiAgICAgICAgcmV0dXJuIHRoaXMub3BlblVybCgibWFpbHRvOj90bz0iICsgZW5jb2RlVVJJQ29tcG9uZW50KHJlY2lwaWVudCkgKyAiJnN1YmplY3Q9IiArIGVuY29kZVVSSUNvbXBvbmVudChzdWJqZWN0KSArICImYm9keT0iICsgZW5jb2RlVVJJQ29tcG9uZW50KG1lc3NhZ2UpLCBjYWxsYmFjayk7CiAgICAgIH0gZWxzZSB7CiAgICAgICAgcmV0dXJuIHRoaXMuZW5xdWV1ZSgiY29tcG9zZUVtYWlsIiwgewogICAgICAgICAgcmVjaXBpZW50OiByZWNpcGllbnQsCiAgICAgICAgICBzdWJqZWN0OiBzdWJqZWN0LAogICAgICAgICAgbWVzc2FnZTogbWVzc2FnZSwKICAgICAgICAgIGNhbGxiYWNrOiBjYWxsYmFjawogICAgICAgIH0pOwogICAgICB9CiAgICB9OwoKICAgIE1NRGV2aWNlLnByb3RvdHlwZS5nZXRDb21wYXNzSGVhZGluZyA9IGZ1bmN0aW9uKGNhbGxiYWNr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vVVJJOiBjYWNoZWRWaWRlb1VSSSwKICAgICAgICAgICAgc3RyZWFtVmlkZW9VUkk6IHN0cmVhbVZpZGVvVVJJLAogICAgICAgICAgICB0b3VjaENhbGxiYWNrOiB0b3VjaENhbGxiYWNrLAogICAgICAgICAgICBjYWNoZWRWaWRlb0lEOiBjYWNoZWRWaWRlb0lELAogICAgICAgICAgICBhdXRvUGxheTogYXV0b1BsYXksCiAgICAgICAgICAgIHNob3dDb250cm9sczogc2hvd0NvbnRyb2xzLAogICAgICAgICAgICBjYWxsYmFjazogY2FsbGJhY2sKICAgICAgICAgIH0pOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICByZXR1cm4gY2FsbGJhY2soewogICAgICAgICAgICAicmVzdWx0IjogMCwKICAgICAgICAgICAgInJlc3BvbnNlIjogImNhY2hlZFZpZGVvVVJJIG9yIHN0cmVhbVZpZGVvVVJJIG5vdCBmb3VuZCIsCiAgICAgICAgICAgICJjbGFzcyI6ICJNTUlubGluZVZpZGVvIiwKICAgICAgICAgICAgImNhbGwiOiAiaW5zZXJ0VmlkZW8iCiAgICAgICAgICB9KTsKICAgICAgICB9CiAgICAgIH0gZWxzZSB7CiAgICAgICAgcmV0dXJuIGNhbGxiYWNrKHsKICAgICAgICAgICJyZXN1bHQiOiAwLAogICAgICAgICAgInJlc3BvbnNlIjogIkRpdiBJZCBub3QgZm91bmQiLAogICAgICAgICAgImNsYXNzIjogIk1NSW5saW5lVmlkZW8iLAogICAgICAgICAgImNhbGwiOiAiaW5zZXJ0VmlkZW8iCiAgICAgICAgfSk7CiAgICAgIH0KICAgIH07CgogICAgTU1JbmxpbmVWaWRlby5wcm90b3R5cGUuaW5zZXJ0VmlkZW8gPSBmdW5jdGlvbih0aW1pbmdDYWxsYmFjaywgY2FsbGJhY2spIHsKICAgICAgcmV0dXJuIHRoaXMuaW5zZXJ0VmlkZW9XaXRoSWQoJ2lubGluZVZpZGVvJywgdGltaW5nQ2FsbGJhY2ssIGNhbGxiYWNrK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7CiAgICAgIGlmICh0aGlzLnRpbWluZ0NhbGxiYWNrICE9IG51bGwpIHsKICAgICAgICByZXR1cm4gdGhpcy50aW1pbmdDYWxsYmFjayhjdXJyZW50U2Vla1RpbWUpOwogICAgICB9CiAgICB9OwoKICAgIE1NQ2FjaGVkVmlkZW8ucHJvdG90eXBlLnNldFRpbWluZ0NhbGxiYWNrID0gZnVuY3Rpb24odGltaW5nQ2FsbGJhY2spIHsKICAgICAgcmV0dXJuIHRoaXMudGltaW5nQ2FsbGJhY2sgPSB0aW1pbmdDYWxsYmFjazsKICAgIH07CgogICAgTU1DYWNoZWRWaWRlby5wcm90b3R5cGUuc2V0RXJyb3IgPSBmdW5jdGlvbihlcnJvcikgewogICAgICBpZiAodGhpcy5lcnJvckNhbGxiYWNrICE9IG51bGwpIHsKICAgICAgICByZXR1cm4gdGhpcy5lcnJvckNhbGxiYWNrKGVycm9yKTsKICAgICAgfQogICAgfTsKCiAgICBNTUNhY2hlZFZpZGVvLnByb3RvdHlwZS5zZXRFcnJvckNhbGxiYWNrID0gZnVuY3Rpb24oZXJyb3JDYWxsYmFjaykgewogICAgICByZXR1cm4gdGhpcy5lcnJvckNhbGxiYWNrID0gZXJyb3JDYWxsYmFjazsKICAgIH07CgogICAgTU1DYWNoZWRWaWRlby5wcm90b3R5cGUucmVzdGFydFZpZGVvID0gZnVuY3Rpb24oY2FsbGJhY2spIHsKICAgICAgcmV0dXJuIHRoaXMuZW5xdWV1ZSgicmVzdGFydFZpZGVvIiwgewogICAgICAgIGNhbGxiYWNrOiBjYWxsYmFjawogICAgICB9KTsKICAgIH07CgogICAgTU1DYWNoZWRWaWRlby5wcm90b3R5cGUuZW5kVmlkZW8gPSBmdW5jdGlvbihjYWxsYmFjaykgewogICAgICByZXR1cm4gdGhpcy5lbnF1ZXVlKCJlbmRWaWRlbyIsIHsKICAgICAgICBjYWxsYmFjazogY2FsbGJhY2sKICAgICAgfSk7CiAgICB9OwoKICAgIE1NQ2FjaGVkVmlkZW8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azsKICAgICAgdGhpcy51dGlscyA9IE1NSlMudXRpbHM7CiAgICAgIHRoaXMucHJvcGVydGllcyA9IHsKICAgICAgICB3aWR0aDogbnVsbCwKICAgICAgICBoZWlnaHQ6IG51bGwsCiAgICAgICAgdXNlQ3VzdG9tQ2xvc2U6IGZhbHNlLAogICAgICAgIGlzTW9kYWw6IHRydWUKICAgICAgfTsKICAgICAgdGhpcy5vcmllbnRhdGlvblByb3BlcnRpZXMgPSB7CiAgICAgICAgYWxsb3dPcmllbnRhdGlvbkNoYW5nZTogdHJ1ZSwKICAgICAgICBmb3JjZU9yaWVudGF0aW9uOiAnbm9uZScKICAgICAgfTsKICAgICAgdGhpcy5yZXNpemVQcm9wZXJ0aWVzID0gewogICAgICAgIHdpZHRoOiBudWxsLAogICAgICAgIGhlaWdodDogbnVsbCwKICAgICAgICBjdXN0b21DbG9zZVBvc2l0aW9uOiAndG9wLXJpZ2h0JywKICAgICAgICBvZmZzZXRYOiAwLAogICAgICAgIG9mZnNldFk6IDAsCiAgICAgICAgYWxsb3dPZmZzY3JlZW46IHRydWUKICAgICAgfTsKICAgICAgdGhpcy5saXN0ZW5lcnMgPSB7fTsKICAgIH0KCiAgICBNUkFJRC5wcm90b3R5cGUuZ2V0QWRTaXplID0gZnVuY3Rpb24oKSB7CiAgICAgIGlmICh0aGlzLnNkay5hZFNpemUgIT0gbnVsbCkgewogICAgICAgIHRoaXMudXRpbHMuY29uc29sZUxvZygiTVJBSUQgZ2V0QWRTaXplICIgKyBKU09OLnN0cmluZ2lmeSh0aGlzLnNkay5hZFNpemUpKTsKICAgICAgICBpZiAodGhpcy5zZGsuYWRTaXplWyJoZWlnaHQiXSA+IDAgJiYgdGhpcy5zZGsuYWRTaXplWyJ3aWR0aCJdID4gMCkgewogICAgICAgICAgcmV0dXJuIHRoaXMuc2RrLmFkU2l6ZTsKICAgICAgICB9CiAgICAgIH0KICAgICAgcmV0dXJuIG51bGw7CiAgICB9OwoKICAgIE1SQUlELnByb3RvdHlwZS5jYWxsYmFja01hbmFnZXIgPSBmdW5jdGlvbihyZXNwb25zZSkgewogICAgICB2YXIga2xhc3MsIG1ldGhvZCwgcmVzcG9uc2VfZGF0YSwgcmVzdWx0OwogICAgICByZXN1bHQgPSByZXNwb25zZVsncmVzdWx0J107CiAgICAgIG1ldGhvZCA9IHJlc3BvbnNlWydjYWxsJ107CiAgICAgIHJlc3BvbnNlX2RhdGEgPSByZXNwb25zZVsncmVzcG9uc2UnXTsKICAgICAga2xhc3MgPSByZXNwb25zZVsnY2xhc3MnXTsKICAgICAgcmV0dXJuIHRoaXM7CiAgICB9OwoKICAgIE1SQUlELnByb3RvdHlwZS5nZXRWZXJzaW9uID0gZnVuY3Rpb24oKSB7CiAgICAgIHJldHVybiAiMi4wIjsKICAgIH07CgogICAgTVJBSUQucHJvdG90eXBlLmNsb3NlID0gZnVuY3Rpb24oKSB7CiAgICAgIHJldHVybiBNTUpTLmludGVyc3RpdGlhbC5jbG9zZSgoZnVuY3Rpb24ocmVzcG9uc2UpIHsKICAgICAgICBpZiAocmVzcG9uc2VbJ3Jlc3VsdCddIDwgMSkgewogICAgICAgICAgcmV0dXJuIG1yYWlkLmZpcmVFdmVudENhbGxiYWNrcygiZXJyb3IiLCAiQ2xvc2UgZmFpbGVkIiwgImNsb3NlIik7CiAgICAgICAgfQogICAgICB9KSk7CiAgICB9OwoKICAgIE1SQUlELnByb3RvdHlwZS5leHBhbmQgPSBmdW5jdGlvbihfdXJsKSB7CiAgICAgIHZhciBrLCBtYXhTaXplLCBwcm9wcywgdiwgX3JlZjsKICAgICAgdGhpcy51dGlscy5jb25zb2xlTG9nKCdtcmFpZC5leHBhbmQgY2FsbGVkIHdpdGggcHJvcGVydGllczogJyArIEpTT04uc3RyaW5naWZ5KHRoaXMuZ2V0RXhwYW5kUHJvcGVydGllcygpKSk7CiAgICAgIHRoaXMudXRpbHMuY29uc29sZUxvZygnbXJhaWQuZXhwYW5kIHVybDogJyArIF91cmwpOwogICAgICBwcm9wcyA9IHRoaXMuZ2V0RXhwYW5kUHJvcGVydGllcygpOwogICAgICBtYXhTaXplID0gdGhpcy5nZXRNYXhTaXplKCk7CiAgICAgIGlmICgocHJvcHMgIT0gbnVsbCkgJiYgKG1heFNpemUgIT0gbnVsbCkpIHsKICAgICAgICBpZiAocHJvcHNbImhlaWdodCJdID09PSBtYXhTaXplWyJoZWlnaHQiXSAmJiBwcm9wc1sid2lkdGgiXSA9PT0gbWF4U2l6ZVsid2lkdGgiXSkgewogICAgICAgICAgcHJvcHNbImhlaWdodCJdID0gdm9pZCAwOwogICAgICAgICAgcHJvcHNbIndpZHRoIl0gPSB2b2lkIDA7CiAgICAgICAgfQogICAgICB9CiAgICAgIF9yZWYgPSB0aGlzLm9yaWVudGF0aW9uUHJvcGVydGllczsKICAgICAgZm9yIChrIGluIF9yZWYpIHsKICAgICAgICB2ID0gX3JlZltrXTsKICAgICAgICBwcm9wc1trXSA9IHY7CiAgICAgIH0KICAgICAgcmV0dXJuIE1NSlMuaW50ZXJzdGl0aWFsLmV4cGFuZFdpdGhQcm9wZXJ0aWVzKF91cmwsIHByb3BzLCAoZnVuY3Rpb24ocmVzcG9uc2UpIHsKICAgICAgICBpZiAocmVzcG9uc2VbJ3Jlc3VsdCddIDwgMSkgewogICAgICAgICAgcmV0dXJuIG1yYWlkLmZpcmVFdmVudENhbGxiYWNrcygiZXJyb3IiLCAiRXhwYW5kIGZhaWxlZCIsICJleHBhbmQiKTsKICAgICAgICB9CiAgICAgIH0pKTsKICAgIH07CgogICAgTVJBSUQucHJvdG90eXBlLm9wZW4gPSBmdW5jdGlvbihfdXJsKSB7CiAgICAgIHJldHVybiBNTUpTLmludGVyc3RpdGlhbC5vcGVuKF91cmwsIChmdW5jdGlvbihyZXNwb25zZSkgewogICAgICAgIGlmIChyZXNwb25zZVsncmVzdWx0J10gPCAxKSB7CiAgICAgICAgICByZXR1cm4gbXJhaWQuZmlyZUV2ZW50Q2FsbGJhY2tzKCJlcnJvciIsICJPcGVuI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IHsKICAgICAgdmFyIGluZGV4OwogICAgICBpZiAodGhpcy5saXN0ZW5lcnNbZXZlbnRdICE9IG51bGwpIHsKICAgICAgICBpZiAobGlzdGVuZXIgIT0gbnVsbCkgewogICAgICAgICAgaW5kZXggPSB0aGlzLmxpc3RlbmVyc1tldmVudF0uaW5kZXhPZihsaXN0ZW5lcik7CiAgICAgICAgICBpZiAoaW5kZXggPCAwKSB7CiAgICAgICAgICAgIHRoaXMudXRpbHMuY29uc29sZUxvZygiTGlzdG5lciBub3QgZm91bmQhIik7CiAgICAgICAgICAgIHJldHVybiBmYWxzZTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHRoaXMudXRpbHMuY29uc29sZUxvZygiJyIgKyBldmVudCArICInIGZvdW5kIGxpc3RlbmVyOiAiICsgbGlzdGVuZXIpOwogICAgICAgICAgfQogICAgICAgICAgdGhpcy5saXN0ZW5lcnNbZXZlbnRdLnNwbGljZShpbmRleCwgMSk7CiAgICAgICAgICByZXR1cm4gdGhpcy51dGlscy5jb25zb2xlTG9nKCInIiArIGV2ZW50ICsgIicgbGlzdGVuZXJzOiAiICsgdGhpcy5saXN0ZW5lcnNbZXZlbnRdKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgcmV0dXJuIGRlbGV0ZSB0aGlzLmxpc3RlbmVyc1tldmVudF07CiAgICAgICAgfQogICAgICB9CiAgICB9OwoKICAgIE1SQUlELnByb3RvdHlwZS5hZGRFdmVudExpc3RlbmVyID0gZnVuY3Rpb24oZXZlbnQsIGxpc3RlbmVyKSB7CiAgICAgIGlmICghKHRoaXMubGlzdGVuZXJzW2V2ZW50XSAhPSBudWxsKSkgewogICAgICAgIHRoaXMubGlzdGVuZXJzW2V2ZW50XSA9IFtdOwogICAgICB9CiAgICAgIHRoaXMudXRpbHMuY29uc29sZUxvZygiJyIgKyBldmVudCArICInIGFkZGVkIGxpc3RlbmVyOiAiICsgbGlzdGVuZXIpOwogICAgICB0aGlzLmxpc3RlbmVyc1tldmVudF0ucHVzaChsaXN0ZW5lcik7CiAgICAgIHJldHVybiB0aGlzLnV0aWxzLmNvbnNvbGVMb2coIiciICsgZXZlbnQgKyAiJyBsaXN0ZW5lcnM6ICIgKyB0aGlzLmxpc3RlbmVyc1tldmVudF0pOwogICAgfTsKCiAgICBNUkFJRC5wcm90b3R5cGUuZmlyZUV2ZW50Q2FsbGJhY2tzID0gZnVuY3Rpb24oZXZlbnROYW1lLCBwYXJhbWV0ZXIsIGFjdGlvbikgewogICAgICB2YXIgY2FsbGJhY2ssIF9pLCBfbGVuLCBfcmVmOwogICAgICB0aGlzLnV0aWxzLmNvbnNvbGVMb2coImV2ZW50IGNhbGxiYWNrOiAiICsgZXZlbnROYW1lKTsKICAgICAgaWYgKHRoaXMubGlzdGVuZXJzW2V2ZW50TmFtZV0gIT0gbnVsbCkgewogICAgICAgIF9yZWYgPSB0aGlzLmxpc3RlbmVyc1tldmVudE5hbWVdOwogICAgICAgIGZvciAoX2kgPSAwLCBfbGVuID0gX3JlZi5sZW5ndGg7IF9pIDwgX2xlbjsgX2krKykgewogICAgICAgICAgY2FsbGJhY2sgPSBfcmVmW19pXTsKICAgICAgICAgIGlmIChwYXJhbWV0ZXIgIT0gbnVsbCkgewogICAgICAgICAgICBpZiAoYWN0aW9uICE9IG51bGwpIHsKICAgICAgICAgICAgICBjYWxsYmFjayhwYXJhbWV0ZXIsIGFjdGlvbik7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgY2FsbGJhY2socGFyYW1ldGVyKTsKICAgICAgICAgICAgfQogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgY2FsbGJhY2soKTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgIH07CgogICAgTVJBSUQucHJvdG90eXBlLnJlc2l6ZSA9IGZ1bmN0aW9uKCkgewogICAgICB2YXIgY2FsbGVkcmVzaXplUHJvcGVydGllcywgbWF4U2l6ZTsKICAgICAgbWF4U2l6ZSA9IHR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IHsKICAgICAgICAgICJoZWlnaHQiOiB0aGlzLnNkay5hZFByb3BlcnRpZXNbIm1heFNpemUiXVsiaGVpZ2h0Il0sCiAgICAgICAgICAid2lkdGgiOiB0aGlzLnNkay5hZFByb3BlcnRpZXNbIm1heFNpemUiXVsid2lkdGgiXQogICAgICAgIH07CiAgICAgIH0gZWxzZSB7CiAgICAgICAgdGhpcy5maXJlRXZlbnRDYWxsYmFja3MoImVycm9yIiwgIm1heCBzaXplIGlzIHVuYXZhaWxhYmxlIiwgImdldE1heFNpemUiKTsKICAgICAgfQogICAgICByZXR1cm4gbnVsbDsKICAgIH07CgogICAgTVJBSUQucHJvdG90eXBlLmdldERlZmF1bHRQb3NpdGlvbiA9IGZ1bmN0aW9uKCkgewogICAgICByZXR1cm4gdGhpcy5zZGsuZGVmYXVsdFBvc2l0aW9uOwogICAgfTsKCiAgICBNUkFJRC5wcm90b3R5cGUuZ2V0U2NyZWVuU2l6ZSA9IGZ1bmN0aW9uKCkgewogICAgICBNTUpTLnV0aWxzLmNvbnNvbGVMb2coImdldFNjcmVlblNpemU6ICIgKyB0aGlzLnNkay5hZFByb3BlcnRpZXNbInNjcmVlbiJdKTsKICAgICAgaWYgKHRoaXMuc2RrLmFkUHJvcGVydGllc1sic2NyZWVuIl0gIT0gbnVsbCkgewogICAgICAgIHJldHVybiB0aGlzLnNkay5hZFByb3BlcnRpZXNbInNjcmVlbiJdOwogICAgICB9IGVsc2UgewogICAgICAgIHRoaXMuZmlyZUV2ZW50Q2FsbGJhY2tzKCJlcnJvciIsICJTY3JlZW4gc2l6ZSBpcyB1bmF2YWlsYWJsZSIsICJnZXRTY3JlZW5TaXplIik7CiAgICAgIH0KICAgICAgcmV0dXJuIG51bGw7CiAgICB9OwoKICAgIE1SQUlELnByb3RvdHlwZS5zdXBwb3J0cyA9IGZ1bmN0aW9uKGZlYXR1cmUpIHsKICAgICAgaWYgKGZlYXR1cmUgIT0gbnVsbCkgewogICAgICAgIHJldHVybiB0aGlzLnN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J2YWwoZnVuY3Rpb24oKSB7CiAgICAgIHZhciBjb21tYW5kOwogICAgICBpZiAoTU1KUy5zZGsuc3RhdGUgIT09ICJsb2FkaW5nIikgewogICAgICAgIGlmIChNTUpTLmV4ZWN1dGluZ0NvbW1hbmQgPT09IGZhbHNlICYmIE1NSlMuY29tbWFuZFF1ZXVlLmxlbmd0aCA+IDAgJiYgTU1KUy5leGVjdXRpbmdDb21tYW5kRGVsYXkgPT09IDApIHsKICAgICAgICAgIGNvbW1hbmQgPSBNTUpTLmNvbW1hbmRRdWV1ZS5zaGlmdCgpOwogICAgICAgICAgTU1KUy51dGlscy5jb25zb2xlTG9nKCJydW5uaW5nIGNvbW1hbmQ6ICIgKyBjb21tYW5kLnVybCk7CiAgICAgICAgICB0cnkgewogICAgICAgICAgICByZXR1cm4gY29tbWFuZC5wZXJmb3JtKCk7CiAgICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICAgIHJldHVybiBNTUpTLnV0aWxzLmNvbnNvbGVMb2coIkZhaWxlZCB0byBydW4gY29tbWFuZDogIiArIGUubWVzc2FnZWFsZXJ0KTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgIH0sIDEpOwogIH0pKCkpOwp9Cg==");
    boolean bool1 = false;
    if (arrayOfByte1 != null)
    {
      bool1 = false;
      if (arrayOfByte2 != null)
      {
        byte[] arrayOfByte3 = new byte[arrayOfByte1.length + arrayOfByte2.length];
        System.arraycopy(arrayOfByte1, 0, arrayOfByte3, 0, arrayOfByte1.length);
        System.arraycopy(arrayOfByte2, 0, arrayOfByte3, arrayOfByte1.length, arrayOfByte2.length);
        boolean bool2 = saveMRaid(paramContext, new ByteArrayInputStream(arrayOfByte3));
        bool1 = false;
        if (bool2)
        {
          storeMraidUrl(paramContext, paramString);
          bool1 = true;
        }
      }
    }
    return bool1;
  }

  // ERROR //
  static boolean saveMRaid(Context paramContext, java.io.InputStream paramInputStream)
  {
    // Byte code:
    //   0: new 86	java/io/File
    //   3: dup
    //   4: aload_0
    //   5: invokestatic 151	com/millennialmedia/android/AdCache:getCacheDirectory	(Landroid/content/Context;)Ljava/io/File;
    //   8: ldc 16
    //   10: invokespecial 154	java/io/File:<init>	(Ljava/io/File;Ljava/lang/String;)V
    //   13: astore_2
    //   14: ldc_w 279
    //   17: iconst_1
    //   18: anewarray 4	java/lang/Object
    //   21: dup
    //   22: iconst_0
    //   23: aload_2
    //   24: aastore
    //   25: invokestatic 283	com/millennialmedia/android/MMSDK$Log:v	(Ljava/lang/String;[Ljava/lang/Object;)V
    //   28: aconst_null
    //   29: astore_3
    //   30: new 285	java/io/FileOutputStream
    //   33: dup
    //   34: aload_2
    //   35: invokespecial 286	java/io/FileOutputStream:<init>	(Ljava/io/File;)V
    //   38: astore 4
    //   40: sipush 1024
    //   43: newarray byte
    //   45: astore 11
    //   47: aload_1
    //   48: aload 11
    //   50: invokevirtual 289	java/io/InputStream:read	([B)I
    //   53: istore 12
    //   55: iload 12
    //   57: ifgt +15 -> 72
    //   60: aload 4
    //   62: ifnull +8 -> 70
    //   65: aload 4
    //   67: invokevirtual 290	java/io/FileOutputStream:close	()V
    //   70: iconst_1
    //   71: ireturn
    //   72: aload 4
    //   74: aload 11
    //   76: iconst_0
    //   77: iload 12
    //   79: invokevirtual 294	java/io/FileOutputStream:write	([BII)V
    //   82: goto -35 -> 47
    //   85: astore 7
    //   87: aload 4
    //   89: astore_3
    //   90: aload_2
    //   91: ifnull +8 -> 99
    //   94: aload_2
    //   95: invokevirtual 297	java/io/File:delete	()Z
    //   98: pop
    //   99: iconst_1
    //   100: anewarray 4	java/lang/Object
    //   103: astore 8
    //   105: aload 8
    //   107: iconst_0
    //   108: aload 7
    //   110: invokevirtual 300	java/lang/Exception:getMessage	()Ljava/lang/String;
    //   113: aastore
    //   114: ldc_w 302
    //   117: aload 8
    //   119: invokestatic 305	com/millennialmedia/android/MMSDK$Log:e	(Ljava/lang/String;[Ljava/lang/Object;)V
    //   122: aload_3
    //   123: ifnull +7 -> 130
    //   126: aload_3
    //   127: invokevirtual 290	java/io/FileOutputStream:close	()V
    //   130: iconst_0
    //   131: ireturn
    //   132: astore 13
    //   134: aload 13
    //   136: invokevirtual 308	java/io/IOException:printStackTrace	()V
    //   139: goto -69 -> 70
    //   142: astore 9
    //   144: aload 9
    //   146: invokevirtual 308	java/io/IOException:printStackTrace	()V
    //   149: goto -19 -> 130
    //   152: astore 5
    //   154: aload_3
    //   155: ifnull +7 -> 162
    //   158: aload_3
    //   159: invokevirtual 290	java/io/FileOutputStream:close	()V
    //   162: aload 5
    //   164: athrow
    //   165: astore 6
    //   167: aload 6
    //   169: invokevirtual 308	java/io/IOException:printStackTrace	()V
    //   172: goto -10 -> 162
    //   175: astore 5
    //   177: aload 4
    //   179: astore_3
    //   180: goto -26 -> 154
    //   183: astore 7
    //   185: aconst_null
    //   186: astore_3
    //   187: goto -97 -> 90
    //
    // Exception table:
    //   from	to	target	type
    //   40	47	85	java/lang/Exception
    //   47	55	85	java/lang/Exception
    //   72	82	85	java/lang/Exception
    //   65	70	132	java/io/IOException
    //   126	130	142	java/io/IOException
    //   30	40	152	finally
    //   94	99	152	finally
    //   99	122	152	finally
    //   158	162	165	java/io/IOException
    //   40	47	175	finally
    //   47	55	175	finally
    //   72	82	175	finally
    //   30	40	183	java/lang/Exception
  }

  static void storeMraidUrl(Context paramContext, String paramString)
  {
    if (!TextUtils.isEmpty(paramString))
    {
      SharedPreferences.Editor localEditor = paramContext.getSharedPreferences("MillennialMediaSettings", 0).edit();
      localEditor.putString("KEY_MMJS_URL", paramString);
      localEditor.commit();
    }
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.millennialmedia.android.MRaid
 * JD-Core Version:    0.6.2
 */